tags:

views:

72

answers:

4

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'?

+4  A: 
$("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.

alexn
+1  A: 

Use insertBefore() or insertAfter().

Max Shawabkeh
+1  A: 
// create your element
var $el = $("<div>");

// append after input
$("input.link").after( $el );
Anwar Chandra
A: 

You should really add an id attribute to your input not only for performance but to be sure that you append only after that specific input:

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

if using jquery

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

else

var textBox = document.getElementById("textBox");
var element = document.createElement("<p>Hello</p>");
textBox.parentNode.insertBefore(element, textBox.nextSibling);
Alex LE