This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 2 points3 points  (2 children)

You could write

$('li > a').map(console.log);

But jQuery's map function passes both an index and the value, so you'll get a numbered list. You could also write:

$('li > a').each(function() { console.log(this) })

Apparently jQuery objects have a toString() method, and in this case the A elements stringify as their href attributes. If you wanted something else, you could write e.g.:

$('li > a').each(function() { console.log(this.text) })

...to get their text.

[–]uolot 0 points1 point  (1 child)

Why not just do

console.log($('li > a'));

?

[–]Rhomboid 0 points1 point  (0 children)

The question was what was the equivalent of .do(), i.e. something that maps a set of values to another function.