Need help with my slidetoggle function
I currently have a slidetoggle function which is working great! What my next goal is, is to create a link inside the div that i'm slide toggling, that will close the parent div that it is in.
Here my code so far...
- /*JQ - EXPAND PANELS ON CLICK*/
- $('#panels .expand').click(function(e){
- e.preventDefault();
- var mclass=$(this).attr('class').split(' ')[1];
- var $mcontent = $("#" + mclass);
-
- $mcontent.slideToggle('slow', function(){
- mthis = $(this);
- if (mthis.is(':hidden')) {
- mthis.prev().css({'background-image':'url("images/arrow-down.png")'});
- }
- else {
- mthis.prev().css({'background-image':'url("images/arrow-up.png")'});
- var menulink = $(this).children().children().next().next('a:last').attr('class');
- //console.log('where am i? '+ menulink);
- $('.'+ menulink).click(function(e) {
- e.preventDefault();
- $mcontent.toggle();
- mthis.prev().css({'background-image':'url("images/arrow-down.png")'});
- });
-
- }
- });
- });
If you look at lines 16 - 20, you will see that I'm trying to click on an internal link to have the same effect as $mcontent on line 8 - basically to slidetoggle where I am at. But it's acting buggy when I click that link (the link associated to lines 16 - 20 in code), (sometimes it closes the div, other times it doesn't).
How can I fix this so that a children() anchor link can bind to the slidetoggle parent function()?
So matter if I am clicking on
$('#panels .expand')
or the internal anchor link, it will slidetoggle the entire function properly.
Thanks!
*Break through the ice and never look back*