Javascript toggle using custom attributes

Posted by Jacob on Stack Overflow See other posts from Stack Overflow or by Jacob
Published on 2014-08-18T21:37:31Z Indexed on 2014/08/18 22:20 UTC
Read the original article Hit count: 207

Filed under:
|
|

Can't seem to get this to work for me, can anyone offer me some help?

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

This should open and close a section of text based on click, it takes the ID # which is just a digit (1,2,3,4,etc) and using that id targets an id to open and close the section.

Javascript

$(document).ready(function(){

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

HTML

<div class="classes">
    <?php foreach ($classes as $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 To Know:
                        asdfasd
                        asdf
                        afsdadfs

                        fsda
                        dfsa
                        dfsadfsa
                    </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>
</div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery