css - jQuery On Click Add Class -


so trying figure out why not work:

https://jsfiddle.net/bv6ort3g/

html:

<div class="all-btn">all button</div>  <div class="item all"> item 1 </div> <div class="item all"> item 2 </div> <div class="item all"> item 3 </div> <div class="item all"> item 4 </div> <div class="item all"> item 5 </div> 

css:

.all-btn {     cursor: pointer;     padding: 5px;     border: 1px solid #000;     display: inline-block;     margin-bottom: 15px; }  .item {     display: none; } .show {     display: block; } 

jquery:

$('.all-btn').on('click', function () {     $('.all').addclass('show'); }); 

basically want click button add class of show div tags class of all

anyone know going wrong?

thanks

basically i've done this...

$(function(){     $(".item").hide();     $(".all-btn").on("click", function(){         $(".item").show();     }); }); 

or can use toggle between classes showing , hiding...

$(function(){     $(".item").hide();     $(".all-btn").on("click", function(){         $(".item").toggle();     }); }); 

i've kept html same...

<div class="all-btn">show button</div>  <div class="item all">item 1</div> <div class="item all">item 2 </div> <div class="item all">item 3 </div> <div class="item all">item 4 </div> <div class="item all">item 5 </div> 

however have removed .item , .show , retained .all-button css code, isn't necessary work.

demo: https://jsfiddle.net/bv6ort3g/1/

fancier demo: https://jsfiddle.net/bv6ort3g/2/


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -