sasori
sasori

Reputation: 5463

how to loop and append a <br> tag to each of array of anchor of tags?

I have an number of achor elements, how to loop through each and add a
tag ? it's like this,

<a id="fbutton" href="http://www.facebook.com" title="fb" name="fb[]">
 <img alt="fb" src="/images/icons/fb.jpg">
</a>

why do i want to add a br tag, because this button is too close to another button with another array name

Upvotes: 0

Views: 2591

Answers (4)

Akhil Thayyil
Akhil Thayyil

Reputation: 9413

Try this , no looping is required ..

 $("a").after("<br/>");

For reference http://api.jquery.com/after/

Upvotes: 2

Darkwater
Darkwater

Reputation: 1386

Give all a elements you want to loop through a class, then use:

$("a.classyougavethem").after("<br/>");

Upvotes: 1

soonji
soonji

Reputation: 79

you dont have to loop it...

$('a').after('<br>');

Upvotes: 0

xdazz
xdazz

Reputation: 160893

You could use .after()

$('a').each(function() {
  $(this).after('<br>');
});

Or just $('a').after('<br>'); if you don't need to do extra logic in the each callback function.

Upvotes: 3

Related Questions