- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › (this) selector
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 :)
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.
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.
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