jQuery .before() inserts content before target element; difference between .before() and .insertBefore();
<script>
$(function() {
$('div').before($('<em>before text - </em>'));
$('p').before($('<em>').attr('title', 'text title attr').text('before text with title attr - '));
});
</script> |
<script>
$(function() {
$('div').before($('<em>before text - </em>'));
$('p').before($('<em>').attr('title', 'text title attr').text('before text with title attr - '));
});
</script>
<div>div</div>
<p>paragraph</p> |
<div>div</div>
<p>paragraph</p>