jquery - Javascript toggle using custom attributes -


can't seem work me, can offer me help?

http://codepen.io/anon/pen/kabjc

this should open , close section of text based on click, takes id # digit (1,2,3,4,etc) , using id targets id open , close section.

javascript

$(document).ready(function(){      $('.classclick').click(function(){    $('#class'+$(this).attr('data-id')+"show").show(400);     }); }); 

html

<div class="classes">     <?php foreach ($classes $class): ?>         <div class="class">             <div class="classclick" data-id="<?=$class['cid']?>">                 <div class="class-title">                     <?=$class['classname']?>                 </div>                 <div class="class-intensity">                     intensity: <?=$class['classintensity']?>                 </div>             </div>             <div class="class-show hidden" id="class<?=$class['cid']?>show">                 <div class="class-inner-content">                     <div class="two-thirds">                         <?=$class['classdesc']?>    </div>                     <div class="one-third">                         things know:                         asdfasd                         asdf                         afsdadfs                          fsda                         dfsa                         dfsadfsa                     </div>                 </div>             </div>         </div>     <?php endforeach; ?> </div> 

as patrick suggested, might have missed jquery inclusion in codepen, suggest using $.each when using class selector. updated codepen

$('.classclick').each(function(){   $(this).click(function(){    $('#class'+$(this).data('id')+"show").toggle(400);    }); }); 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -