11 Vote

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

Question by Guest | 2013-12-07 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?

ReplyPositiveNegative
-1Best Answer1 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">
  Text.
</div>

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").
2013-12-07 at 21:21

ReplyPositive Negative
Reply

Related Topics

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.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.