How to modify STYLE attribute of element with known ID using JQuery

Viewed 141099

I got 3 buttons-links triggering some javascript code, with indication if certain button is selected, selected button got style attribute set to

"btn brown selected"

while other buttons got this attribute set to

"btn brown"

only one button can be selected at one time, each of buttons got different unique id, my question is how using jquery access certain button to modify it's style attr. What i need its only how to access by id single button and modify its style attribute to get immediate update on the screen

thanks in advance MTH

4 Answers

The question was misleading by confusing the html style attribute and css attributes.

However, if you want to actually modify the style attribute of an html element using jQuery, just reassign the entire style attribute like this:

<div id="mydiv" style="position:absolute; right:0; display:block;">
</div>

<script>
    // change position to relative and remove "right" and "display" css attributes
    $('#mydiv').attr("style", "position:relative;");
</script>
Related