开发者

change the Style Attribute value

How can I get and change the Style Attribute property value

开发者_如何学JAVA

Example

<div id="styleChanger" style="color: rgb(163, 41, 41);">
   // some content
</div>

How can I change the Style property color value


Every CSS declaration, inline (a.k.a style attribute), in the page header or in an external file, is just incorporated into the DOM object attributes once the browser has read it.

This is to say that you're not actually interested in changing the style attribute, but an attribute of the object you're working on in Javascript. For CSS attributes, jQuery's .css() method is the answer.

$('#styleChanger').css("color","red");


You need a ready class, for example:

.interactClass {
    color: #d2232a;
}

and then you can

$('#styleChanger').removeClass().addClass('interactClass');

Or you can switch single properties with css method:

$('#styleChanger').css("color", "#D2232A").css("font-size", "20px");


Use the css() method in jQuery. Here is a link to the documentation: http://docs.jquery.com/CSS/css#name

This will allow you to do something like:

$("#styleChanger").css("color", "#888888");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜