Reputation: 35
How to use this? I am studying the jQuery Cookbook and I'm new. I can't figure out on how to make this code work.
var anchors = jQuery('a');
// #1
anchors.children();
// #2
jQuery('> *', anchors);
// #3
anchors.find('> *');
The thing is, I'm trying to select all the child <a>
tags on the list using the variable and children which is the code above according to the cookbook.
This is the HTML code:
<ul id="nav">
<li><a href="#anchor1">Anchor 1</a></li>
<li><a href="#anchor2">Anchor 2</a></li>
<li><span><a href="#anchor3">Anchor 3</a></span></li>
</ul>
Upvotes: 1
Views: 93
Reputation: 6420
If I understand correctly you would like to use these statements:
var list = jQuery('ul#nav');
// #1
list.children();
// #2
jQuery('> *', list);
// #3
list.find('> *');
all 3 resuting in the 3 list items ('li')
Here's a fiddles: (nice tool to try stuff out and show people what your question is about)
Upvotes: 1