Home » Jquery » jQuery: Add element after another element

jQuery: Add element after another element

Posted by: admin November 7, 2017 Leave a comment

Questions:

I have a certain textbox and I want to add a div after it.
I’ve tried the .append() function, but that only adds the div in the element.

For example, I have:

<input type="text" id="bla" />

and I want to change that into:

<input type="text" id="bla" /><div id="space"></div>
Answers:

try using the after() method:

$('#bla').after('<div id="space"></div>');

Documentation

Questions:
Answers:

try

.insertAfter()

here

$(content).insertAfter('#bla');

Questions:
Answers:

First of all, input element shouldn’t have a closing tag (from http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT : End tag: forbidden
).

Second thing, you need the after(), not append() function.