Changing Colors

$("h1").on("click", function(){   $(this).css({color:"white",                "background-color":"black"}); });

A great way to provide interaction with user actions is to alter the colors of elements on the screen. Colors can provide additional meaning. For instance, changing the color of text to red or the background color of text to a yellow highlight accentuates the text as important to read.

In jQuery, you can change all the CSS attributes that control the colors on the screen using the .css(property, value) method. However, if you are changing multiple color properties, it makes much more sense to use the .css({property:value, property:value...}) method, which allows you to change several ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.