0

How can I get and change the Style Attribute property value

Example

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

How can I change the Style property color value

3 Answers 3

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

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");

Comments

0

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.