Reputation: 874
here is the problem and its really really killing me becauseit probably has a very simple solution. check out this jsfiddle
<body>
<p>
this is the first paragraph and it will get the prepend without any problems at all
</p>
<span>
this is a simple span element, and it will also get the prepend without any problems at all
</span>
<em>
heres a em and this works as well
</em>
<p>
here is another para and it works , BUT NOW LOOK AT THE NEXT LINE
<br>BR STARTS HERE
where is this prepend, ladies and gentlement,,NADA.
</br>
</p>
$("*", document.body).each(function () {
$(this).prepend('<b><font color="red"> soccer </font></b>');
});
you will find a simple set of HTML tags just a few randomly placed <p>
and <span>
tags.
I have written a small jquery (2 lines function) that loops through all the tags in the body of the page and prepends a piece of html to each tag.
Unfortunately, the <br>
tags do not seem to follow what all the other tags follo. It does not get the prepended HTML and I just can't figure it out.
Upvotes: 0
Views: 294
Reputation: 196187
If you read the specs (http://www.w3.org/TR/html5/text-level-semantics.html#the-br-element) you will see that the content model of br
is empty.
This means that it can not have contents..
Upvotes: 0
Reputation: 33661
It's because a <br/>
tag can't have any children elements or content https://developer.mozilla.org/en-US/docs/HTML/Element/br.. if you use .before()/.after() it will show up as a sibling as you wanted.
Upvotes: 1