Change element in class
I want to just change one of the elements in a class with jQuery
.myClass
{
b开发者_开发问答ackground-color:#FFFFFF;
}
I want to programatically change this
This changes all .myClass elements. You can change multiple properties of the element.
$(".myClass").css({'background-color':'#BBBBBB'});
http://docs.jquery.com/Attributes/addClass
$("p:last").addClass("myclass");
To remove an entire inline style tag:
$('.myClass').removeAttr('style');
http://docs.jquery.com/Attributes/removeAttr#name
jquery doesn't manipulate stylesheets AFAIK. what you can do is change the background-color
of nodes in .myClass:
$('.myClass').css('background-color', '#FF0000');
If you want to add the myClass
class to a DOM element:
myElement.addClass("myClass");
If you want to remove the myClass
class from a DOM element:
myElement.removeClass("myClass");
For more information, see the jQuery docs on hasClass
, addClass
, removeClass
, and toggleClass
.
精彩评论