Reputation: 3788
I want to append <i>Some Text</i>
after the value of the submit button. If I write it in HTML like in the code snippet, it works but if I use jQuery to append it works partially.
By partially I mean if you open Developer Tools, the appended text is present but it doesn't display on the browser screen.
Why does this happen?
$(document).ready(function(){
$('.tryout').append('<i>Hello</i>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input class="tryout" type="submit"></input>
<hr>
<input type="submit"><i>Hello</i></input>
Upvotes: 0
Views: 249
Reputation: 388316
You can't append anything to an input element, use button instead
$(document).ready(function() {
$('.tryout').append('<i>Hello</i>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="tryout" type="submit"></button>
<hr>
<button type="submit"><i>Hello</i></button>
Or if you want you can insert the new element as a sibling of the button using .after() like $('.tryout').after('<i>Hello</i>');
Upvotes: 3
Reputation: 82231
You need to use .after instead of .append()
to append element after certain element:
Insert content, specified by the parameter, after each element in the set of matched elements.
$('.tryout').after('<i>Hello</i>');
Upvotes: 1