Give help. Get help.

  • # July 24, 2009 at 3:57 am

    Hey all. just a quick jQuery question.

    I was wondering if there is a way to use (this) as well as a css selector in a jquery statement for instance

    $("ul li").hover(function() {
    $(this "span.description").slideToggle();
    }, function() {

    $(this "span.description").slideToggle();


    I know this exact example doesn’t work, but i was wondering if there was something similar i could do. thank you :)

    # July 24, 2009 at 6:00 am

    probably not – but only because of the logic of the this selector.

    Remember the point of "this" is that it selects the item that, in this case, triggered the hover. The idea of this is to very specifically target the item like that.

    So to add selectors to it would mean you are trying to select another element, and in that case you should be using another method of selection. Just keep in mind the idea of "this" is to select that specific element and nothing else.

    # July 24, 2009 at 4:40 pm

    You can specify a context when you use jQuery to limit the content that the expression will match against.

    $("span.description", this) will limit the query to the context of this – if this is a DOM element or jQuery object.

    Note that this is not the same as matching two selectors.

    # July 24, 2009 at 6:01 pm

    thanks everyone, what I wanted it for was so that when you mouse over the li it only effected the span.description element in that li. not all of the others as well :-)

    and thanks Dave :-) your idea worked like a charm

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.