views:

41

answers:

3
A: 

just do $('.box').hide();

if this doesn't work then have you tried putting in an alert in the code to see if the event is firing?

or try two parents as apple is a child of the ul and then you get to the box.

it also depends at what point your creating the live code. if you create it on document load then it should work. if however you create it when you create ".box" then it won't work as it hasn't executed.

griegs
$('.box').hide() will hide all boxes. If there was only one, I suspect he would use an ID instead.
Magnar
He's not very specific but yeah an id would be ideal
griegs
i actually tried that too, but that doesnt seem to hide it. the event definitely fires off as i checked it with an alert
st4ck0v3rfl0w
A: 

use .closest().

$('.apple').live('click',function(){
   $(this).closest('.box').hide();
});

or make it in all li of ul with the class="fruits"

$('.fruits li').live('click',function(){
   $(this).closest('.box').hide();
});

updated answer

//pops the menu when productControl is clicked
$('.fruits li').live('click',function(e){ // pass e as parameter...
   e.stopPropagation();
   $(this).closest('.box').hide();
});

use .stopPropagation() to stop it's parent calling it's click handler which is $(".productControl").live('click',function(){...}); making it showing again...


another update

$(".productControl").live('click',function(e){
   if ($(e.target).is('li')) return; // <-- add this line...
   //... other codes
});
Reigel
Thanks Reigel, but it wasn't working so I posted more code to be clear.
st4ck0v3rfl0w
please see updated answer... ;)
Reigel
Thanks, great find, but I tried it and still no luck. I checked the reference page you linked and in the comments section someone posted "stopPropagation() doesn't work when using .live() to bind events to elements. This should be documented or fixed."
st4ck0v3rfl0w
okay, let's try my update if that fixes it... ;)
Reigel
A: 

This is the best way to do it:

$('.apple').live('click', function() { 
    $(this).closest(".box").hide();
});

But using parents should also be working (difference is: it will also hide .boxes further up the DOM tree). If it does not work, we may need to see more of your code.

Magnar
The above solutions aren't working. I will post more code to be clear.
st4ck0v3rfl0w