borayeris borayeris - 1 year ago 86
jQuery Question

jQuery: combining after and html methods

As you know in jQuery we can combine methods. But here I have a problem.

$('div').after('<span class="text-warning" >SPAN</span>').html('test');

<script src=""></script>

.html inserts the text in div. Shouldn't it change new element?

Answer Source

No, 'after' is an operator and will return whatever it operated on. In this case, the div.

What you want is something like:

var span = $('<span class="text-warning" >SPAN</span>')