1

I have a switch statement and I must be overlooking something, because I don't see why it wouldn't work.

$('.handles a').click(function() {
    var li = $(this).parent();

    switch ($(li).data('handle')) {
    case 'minimize':
        $('.window', li).hide();
        break;
    }

    return false;
});

Also setup a fiddle @ http://jsfiddle.net/9aHvx/4/ (click on Min)

It should hide the .window div, but it doesn't :(

2
  • 1
    Looking to hide a DIV or LIs in a DIV? Commented Apr 20, 2011 at 22:16
  • OMG I suck. You all rock. Nevermind. I == stupid. Going to bed now :P Thanks for pointing out the obvious :) bows his head in shame Commented Apr 20, 2011 at 22:21

6 Answers 6

3

this line $('.window', li).hide(); is wrong. if you want to target .window and li, you need to write it like you would for css:

$('.window, li').hide();

Edit: Fiddle http://jsfiddle.net/9aHvx/7/

Sign up to request clarification or add additional context in comments.

7 Comments

That does something completly different than what he is asking for.
Nopez. the li is a var. $('.window', li) means .window in li element
In which case it fails because div.window isn't inside an li.
Yes, that is right PeeHaa. But do you really think he wants to hide everything and not just the window? (hm.. on second thought you MIGHT be right, but I think he's just looking for a window to hide the element with the window-class)
I mistook his intention, but either way the li is misplaced.
|
2

Using the syntax:

$('.window', li).hide();

means that you search for an element with the class window, starting from the node li. Objects with the window class that are NOT descendants of li will NOT be matched.

In your markup, this is exactly the case. You should skip the second parameter all together. Or, you could rearrange your markup (but that is probably not what you want).

Go for:

$('.window').hide();

EDIT: This is if you want to hide the window-element only. If you want to hide the li's as well, then goo for shanethehat's solution.

Comments

1

The .window div is not inside the li element, so you don't have to pass the li variable as parameter:

$('.window').hide();

Comments

1

http://jsfiddle.net/9aHvx/13/

Use $('.window').hide(); instead, because there are no <li> inside <div class="window">

Comments

1

Your selector is off

$('.handles a').click(function() {
    var li = $(this).parent();
    var x = $(li).data('handle');
    switch (x) {
    case 'minimize':
        alert(x);
        $('.window').hide();
        break;
    }

    return false;
});

jsFiddle link

2 Comments

Hmmmmm.... So I can't use the jquery selector in the switch statement? That's strange or isn't it? Why is that, anyone?
I mean the $('.window', li) part should have been $('.window, li') sorry if I'm not being clear. I just stored the value into a variable so I can debug it easily using alert.
0

K sorry I wasted your time.

I just made a major boo boo! :P

  $('.handles a').click(function() {

    var snippet = $(this).parents('.snippet');

    switch($(this).parent().data('handle')) {
      case 'minimize':
        $('.window', snippet).hide();
        break;
    }

    return false;
  });

Thanks all :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.