1

I have a html button but i am unable to change it background with Jquery.

<html>
  <head><script type="text/javascript" src="jquery_2x.js"></script><script type="text/javascript" src="func_btns.js"></script> </head>
  <body bgcolor='#454545'><br />
    <form method="POST" action="">
        <input type="button" value="Button #1" name="sname" class="btn2" /><br/><br />
        <input type="button" value="Button #2" name="sclass" class="btn2"/>
    </form>                                 
  </body>
</html>

and Here is func_btns.js File:

$(document).ready(function(){
   $('btn2').css('background-image', 'btna.jpg');
});

Simple JS code work but this peace of code is not working, i have download latest jquery and attach to html page.

Lumi Lu
  • 3,289
  • 1
  • 11
  • 21

2 Answers2

0

Use a . to use class selector , that is $(".btn2")

MK Yung
  • 4,344
  • 6
  • 30
  • 35
0

Here is the similar topic Setting background-image using jQuery CSS property

Try something like this,

 $('.btn2').css('background-image', 'url("btna.jpg")');
Community
  • 1
  • 1
Lumi Lu
  • 3,289
  • 1
  • 11
  • 21