Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add <br/> take after </span> with jquery

Tags:

html

jquery

css

I'm having a twitter feed automatically added by a script. I want to add a <br/> with jquery in it. Now it's like this

    <ul id="twitter_update_list">
    <li><span>something</span> <a  href="#">about 4 hours ago</a></li>
    <li><span>something</span> <a  href="#">about 6 hours ago</a></li>
    </ul>

I want to add a <br/> after each </span> with jquery. so that its like this

 <ul id="twitter_update_list">
    <li><span>something</span><br/> <a  href="#">about 4 hours ago</a></li>
    <li><span>something</span><br/> <a  href="#">about 6 hours ago</a></li>
    </ul>
like image 958
esafwan Avatar asked Nov 15 '10 10:11

esafwan


People also ask

How to add after in jQuery?

jQuery insertAfter() Method The insertAfter() method inserts HTML elements after the selected elements. Tip: To insert HTML elements before the selected elements, use the insertBefore() method.

How to insertBefore in jQuery?

jQuery insertBefore() Method The insertBefore() method inserts HTML elements before the selected elements. Tip: To insert HTML elements after the selected elements, use the insertAfter() method.

How to insert a div after a div in jQuery?

The insertAfter() is an inbuilt method in jQuery which is used to insert some HTML content after a specified element. The HTML content will be inserted after each occurrence of the specified element. Here the “content” is the HTML content which is to be inserted after the specified target.

What does appendTo do in jQuery?

jQuery appendTo() Method The appendTo() method inserts HTML elements at the end of the selected elements. Tip: To insert HTML elements at the beginning of the selected elements, use the prependTo() method.


Video Answer


1 Answers

You can use .after() to insert an element after each the selector matched, like this:

$("#twitter_update_list span").after("<br />");

You can test it out here. The result is...well, exactly what you have in the question :)

like image 76
Nick Craver Avatar answered Sep 18 '22 05:09

Nick Craver