javascript - Remove class added after clicking new button -



javascript - Remove class added after clicking new button -

need help. managed create jquery alter class of button after beingness clicked need click new button class removed others.

i'm trying can not. i've tried way whenever try, can remove , clicked button not new class.

can help me?

class="snippet-code-js lang-js prettyprint-override">$(document).ready(function() { $('div#filters-container button').click(function() { var id_button = $(this).val(); $("#" + id_button + "").addclass("cbp-filter-item-active"); }); }); class="snippet-code-css lang-css prettyprint-override">.cbp-filter-item-active { background-color: #5d5d5d; color: #fff!important; border-color: #5d5d5d } class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="filters-container"> <button value="0" id="0" href="videos2-carrega.asp">todos</button> <button value="1" id="1" href="videos2-carrega.asp?cat=1">família</button> <button value="2" id="2" href="videos2-carrega.asp?cat=2">finanças</button> <button value="3" id="3" href="videos2-carrega.asp?cat=3">propaganda</button> <button value="4" id="4" href="videos2-carrega.asp?cat=4">empreendedorismo</button> </div>

thank attention.

$(document).ready(function() { $('div#filters-container button').click(function() { var id_button = $(this).val(); $("#"+id_button+"").addclass("cbp-filter-item-active"); $(this).siblings().removeclass('cbp-filter-item-active'); //added line }); });

added line of code remove class rest of buttons. demo: http://jsfiddle.net/8oytw0ue/2/

actually, much simpler:

$(document).ready(function() { $('div#filters-container button').click(function() { $(this).addclass("cbp-filter-item-active"); $(this).siblings().removeclass('cbp-filter-item-active'); }); });

you don't need id select button $(this) ok...

javascript jquery addclass removeclass

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -