I have this little code:
$("ul#mainnav > li").hover(function(){
$("ul#mainnav > li > a").slideUp();
})
I just don’t know the right syntax for selecting the direct child <a> using $(this)
What I used is this, and I think its wrong…
$(this).find("> a")
Thank you.
For starters, you have an extra quote. Remove the quote after
this. Like this:Admittedly I’ve never used selectors for this case, so I can’t comment about why it’s not working. Instead, I’d recommend using
children()which is usually faster and, IMHO, clearer.But if you really want to use a string selector, this should work:
Note that the jquery docs say that the latter code will be deprecated at some point, so use with caution. I’d still recommend using
children().