class - Selecting parent div and not every div with the same name with jQuery -


my problem is, when click on div class "trigger" every div "group" opens, parent div should open, how can this?

code

// global variables var nav           = $('.group'),     navheight     = nav.height()+15,     items         = $('.group .item .trigger'),     itemssub      = items.next('.toggle_container'),     itemssubopen  = false,     speed         = 400; // global functions var navopen = function (thissubmenu) {     itemssubopen = true;     // height     thissubmenu.css('height', 'auto');     var thisheight = thissubmenu.height();     thissubmenu         .css('height', '0')         .animate({height: thisheight }, speed)         .addclass('open');      nav.animate({height: thisheight + navheight }, speed); }; var navclose = function () {     itemssubopen = false;     items.next('.open')         .animate({height: 0}, speed)         .removeclass('open');     nav.animate({height: navheight-15 }, speed); }; // prepare css itemssub.css('display', 'block'); itemssub.css('height', '0'); // click event items.click(function(event) {     // set local variables     var thisitem = $(this),         thissubmenu = thisitem.next('.toggle_container');     // conditional click event handling     if ( itemssubopen  ) {         if ( thissubmenu.hasclass('open') ) {             // close             navclose();         } else {             // close old, open new             navclose();             settimeout(function() {                 navopen(thissubmenu);             }, speed);         }     } else {         // open         navopen(thissubmenu);     }     // prevent default     event.preventdefault(); }); 

i have fiddle here example: http://jsfiddle.net/kfcgg/15/ maybe 1 of can me problem.

thanks

the right way refer parent div!

$(this).closest('.group')

will refer parent 'group' class only. hope usefull!


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -