jquery - Fade in div with same class name as the same name as my button id -


i have few buttons share same class name divs ids fade in.

example:

 <div class="one">button</div>   <div id="one">i 1 div needs fade in</div>    <div class="two">button</div>   <div id="two">i 2 div needs fade in</div> 

you should use common class/tag buttons, , data-* attribute target id, , retrieve in click handler:

html:

 <div class="button" data-target="one">button</div>   <div id="one">i 1 div needs fade in</div>    <div class="button" data-target="two">button</div>   <div id="two">i 2 div needs fade in</div> 

js:

$(document).on('click', '.button', function() {   var id = $(this).data('target');   $('#' + id).fadein(); }); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -