1 1 Vote

jQuery: Change Background-Color of HTML-Element using jQuery

Question by Guest | 07/12/2013 at 20:59

I would like to change the background-color of an HTML element with jQuery dynamically.

For example, given the ID of a DIV container, I would like to change the DIVs background to red. Is that possible?


Stefan Trost

Show Profile | Message
-1Best Answer
1 Vote

That should not be a problem with jQuery. You can use the following way:

$("#myid").css("background-color", "#FF0000");

Where the element could be like this:

<div id="myid">

With "#myid", you can address the ID of the element (in this case "myid") and with .css() you can change arbitrary CSS-properties of this element (in this case the property "background-color").
07/12/2013 at 21:21

ReplyPositive Negative

Related Topics

jQuery: Replace element
Question | 1 Answer
jQuery: Change Image
Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own articles on askingbox.com. How to do.