PositiveGuy
PositiveGuy

Reputation: 47733

Change element in class

I want to just change one of the elements in a class with jQuery

.myClass
{
   background-color:#FFFFFF;
}

I want to programatically change this

Upvotes: 0

Views: 183

Answers (5)

just somebody
just somebody

Reputation: 19247

jquery doesn't manipulate stylesheets AFAIK. what you can do is change the background-color of nodes in .myClass:

$('.myClass').css('background-color', '#FF0000');

Upvotes: 1

oliverdore
oliverdore

Reputation: 47

To remove an entire inline style tag:

$('.myClass').removeAttr('style');

http://docs.jquery.com/Attributes/removeAttr#name

Upvotes: 1

Steve Harrison
Steve Harrison

Reputation: 125480

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.

Upvotes: 0

powtac
powtac

Reputation: 41040

http://docs.jquery.com/Attributes/addClass

$("p:last").addClass("myclass");

Upvotes: 1

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

This changes all .myClass elements. You can change multiple properties of the element.

 $(".myClass").css({'background-color':'#BBBBBB'});

Upvotes: 1

Related Questions