January 13, 2016
How to Add Style Using jQuery
To add style using jQuery, we make use of css() function. Example is given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!DOCTYPE html> <html> <head> <title>jQuery Tutorial </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> //Function to apply style. function myStyle(){ $('#divHello').css('background-color','red'); } </script> </head> <body> <input type="button" value="Apply CSS" onclick="myStyle()"/> <br /> <br /> <div id="divHello">Hello World! </div> </body> </html> |