Friday, December 5, 2014

How to define multiple CSS attributes in jQuery

I have been doing like this
$('#id).css('background-color': '#ffff00', );
$('#id).css('color', '#ff0000');

yes it works but Could be done like this using chaining 
$('#id).css('background-color': '#ffff00'.css('color', '#ff0000'); 



But still the better way is to do like this

$('#' + id).css({'background-color': '#ffff00','color': '#ff0000'});
#notice the curly braces Even better way is to simply change class of the element using jquery

No comments:

Post a Comment