tags:

views:

5974

answers:

2

Hello

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

+1  A: 

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

$('#buttonId').css({ 'background-color': 'brown'});
MaxiWheat
better answer, imho. More cleanly articulated without the editorial commentary. +1
Jay Stevens
+1  A: 

Not sure I completely understand the question but:

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

seems to be along the lines of what you want.

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

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

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

cletus
That it was exactly was i looking for Thanks!
MoreThanChaos