alfred
alfred

Reputation: 23

jQuery - Iteration problem

This is probaby really easy for you guys. Its a real hassle for me..

I want to add a new link next to all of my other links.

Could someone help me out? Please!? http://jsfiddle.net/Ahndm/

Upvotes: 2

Views: 76

Answers (1)

Nick Craver
Nick Craver

Reputation: 630379

Instead of $("a") in your loop, use this to reference the current element, like this:

$(this).after("<span> <a href='" + newURL + "" + ID + "'>"+ newPlace + "</a></span>");

Here's the updated/working demo. Any time you're inside a .each() you can use this which is the current DOM element, using $("a") selects all anchors, creating n^2 links.

Upvotes: 1

Related Questions