tags:

views:

993

answers:

3

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"></input>

and I want to change that into:

<input type="text" id="bla"></input><div id="space"></div>
+1  A: 

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.

naivists
Correct, but that's what happens when I try the .append() function.
skerit
If it's XHTML then the input element should be closed (but not with an end tag).
CiscoIPPhone
+1  A: 

try

.insertAfter()

here

$(content).insertAfter('#bla');
Rifat
Shouldn't your code be more like `$('<div id="space"></div>').insertAfter('#bla')` rather than `$('#bla').insertAfter(content);`?
Rowan
thanks for correction :)
Rifat
+2  A: 

try using the 'after()' method:

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

Documentation

Rowan
The .after() and .insertAfter() methods perform the same task.
Rifat
That's correct, but it depends on the way you prefer to code it. I'd normally have the '#bla' input selected already, and then add the extra content afterwards. Purely my preference though, I'm not sure whether either method has a speed benefit.
Rowan