how to match var/id to class

Posted by circey on Stack Overflow See other posts from Stack Overflow or by circey
Published on 2010-06-01T02:16:36Z Indexed on 2010/06/01 2:23 UTC
Read the original article Hit count: 386

Filed under:
|
|
|

Hi. I'm new to jquery and, in addition, I think I'm having a brain freeze.

I have a number of links with different ids. I want to match the clicked link with a div with the corresponding class so the div will show/hide/toggle as appropriate.

I have:

<script type="text/javascript">
$(document).ready(function() {
 $('.folioBox').hide();

 $('a.interface').click(function(){
        var currentId = $(this).attr('id');
        var currentBox = $('.folioBox .' + currentId);

        $(currentBox).toggle(400);

        });
});
</script>


<a class="interface" id="apple">Apple flavor</a>
<a class="interface" id="banana">Banana flavor</a>
<a class="interface" id="cherry">Cherry flavor</a>

<div class="folioBox apple">content</div>
<div class="folioBox banana">content</div>
<div class="folioBox cherry">content</div>

I just can't get it to work and I can't figure out whether I would be best using match or find or filter.

Some assistance would be much appreciated!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about class