[ACCEPTED]-How to modify STYLE attribute of element with known ID using JQuery-css

Accepted answer
Score: 51

Use the CSS function from jQuery to set 1 styles to your items :

$('#buttonId').css({ "background-color": 'brown'});
Score: 40

Not sure I completely understand the question 8 but:

$(":button.brown").click(function() {
  $(":button.brown.selected").removeClass("selected");
  $(this).addClass("selected");
});

seems to be along the lines of what 7 you want.

I would certainly recommend using 6 classes instead of directly setting CSS, which 5 is problematic for several reasons (eg removing 4 styles is non-trivial, removing classes 3 is easy) but if you do want to go that way:

$("...").css("background", "brown");

But 2 when you want to reverse that change, what 1 do you set it to?

Score: 2
$("span").mouseover(function () {
$(this).css({"background-color":"green","font-size":"20px","color":"red"});
});

<div>
Sachin Tendulkar has been the most complete batsman of his time, the most prolific     runmaker of all time, and arguably the biggest cricket icon the game has ever known. His batting is based on the purest principles: perfect balance, economy of movement, precision in stroke-making.
</div>

0

Score: 0

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

However, if 3 you want to actually modify the style attribute 2 of an html element using jQuery, just reassign 1 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>

More Related questions