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

后端 未结 3 1456
终归单人心
终归单人心 2020-12-14 07:15

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 selecte

3条回答
  •  既然无缘
    2020-12-14 07:46

    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?

提交回复
热议问题