Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add an element AFTER another?

Tags:

jquery

when i use append it add an element WITHIN an element. i want to add an element AFTER an element.

eg.

 <div class="link">
       <input class="link" type="text" value="Skriv länk" />
       <br />
 </div>

how do i add an element after 'input' but before 'br'?

like image 305
ajsie Avatar asked Jan 24 '10 10:01

ajsie


2 Answers

$("input").after("<p>Hello</p>");

After on jQuery doc: http://api.jquery.com/after/

You also have the insertAfter:

$("<p>Hello</p>").insertAfter("input");

Will work just fine.

like image 135
alexn Avatar answered Sep 23 '22 07:09

alexn


Use insertBefore() or insertAfter().

like image 36
Max Shawabkeh Avatar answered Sep 21 '22 07:09

Max Shawabkeh