Javascript examples for jQuery Method and Property:css
The css() method sets or gets one or more style properties for the selected elements.
Parameter | Description |
---|---|
property | CSS property name, like "color", "font-weight", etc. |
value | value of the CSS property, like "red", "bold", etc. |
function(index,currentvalue) | a function that returns the new value for the CSS property |
The following code shows how to Set the color property of all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").css("color", "red"); });/*from w w w . j a v a 2 s . c o m*/ }); </script> </head> <body> <button>Set the color property of all p elements</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>