Reputation: 4386
I have a simple input field :
<input type="text" id="someid" name="somename" class="someclass">
I'm trying to append some link right after this; so i'll get :
<input type="text" id="someid" name="somename" class="someclass"> - <a href="#">..</a>
i tried :
$("input#someid.someclass").append(' - <a href="#">Are you sure ?</a>');
Without success, must be stupid but i can't find out what's wrong.
Upvotes: 18
Views: 66675
Reputation: 1
$("input#someid.someclass").after($('<a>')
.attr('href','#').text('Are you sure ?'));
Upvotes: -2
Reputation: 1736
Try .after() instead:
$("input#someid.someclass").after(' - <a href="#">Are you sure ?</a>');
Upvotes: 39
Reputation: 887453
The append
method will add the node you give it to the element you call it on.
In your case, you are putting the HTML inside the INPUT
element.
You need to use the after
method to insert the HTML after your INPUT
element.
Upvotes: 8
Reputation: 7179
Use after instead of append
$("input#someid.someclass").after(' - <a href="#">Are you sure ?</a>');
Upvotes: 72