Reputation: 921
A quickie: In my code
$("iframe").append(" <b>Appended iframe by element</b>.");
is not being appended.
I also found that $("img").append(" <b>Appended p by element</b>.");
also doesn't work.
A fiddle is here: https://jsfiddle.net/stephan_luis/9hqo72ua/8/
jQ select by ID is also tried, both work for a <p></p>
tag.
My question is why doesn't this work? The docs don't mention anything https://api.jquery.com/append/ Is there a list of html element that jquery methods don't 'do'?
Upvotes: 0
Views: 139
Reputation: 943547
This doesn't really have anything to do with jQuery. It is about the HTML you are trying to generate.
append()
adds child elements to an element.
The children of an iframe
element in HTML 4.x were alternative content that is only displayed if the browser doesn't support iframes. Today, iframe
elements aren't allowed children.
Image elements (like iframes) are replaced elements, but they aren't allowed children at all (and never have). <img><b>Appended p by element</b></img>
is just invalid HTML.
The HTML specification tells you what content each element is allowed to have in the entry for that element.
e.g. for iframe it says:
Content model: Nothing.
Upvotes: 2