In your case, when you do:
$('body').prepend('<image></image>');
jQuery will try to convert the string you are trying to add to the dom element before adding it, but the image is not an official tag ( http://www.w3.org/TR/html5/ ), so your browser will create the tag because it thought it was what you want
To force the browser to create the tag that you want, you must tell jQuery that you want to use a special tag using this code:
var $image = $('<image>'); $('body').prepend($image);
this is normal for a browser that allows you to create custom html elements such as chrome and firefox, but it doesnโt work in IE, look at this updated fiddle (Iโll tell you โimage tags 1โ in chrome, but still โimage tags" 0 " in IE):
http://jsfiddle.net/d4s4p3az/1/
So the solution is to create a w3c matching tag using the svg image namespace:
<html> <head> <script src="http://code.jquery.com/jquery-2.1.1.js"></script> </head> <body> <script> $(document).ready(function onDomLoad() { $('svg').append('<image>'); $('svg').append($('<image>')); var svg = document.createElementNS('http://www.w3.org/2000/svg', 'image'); $('svg').append(svg); $('body').append('img tags: '+$('svg').children('img').length+'<br>'); $('body').append('image tags: '+$('svg').children('image').length); }); </script> </body> </html>
Here is the fiddle:
http://jsfiddle.net/d4s4p3az/11/
A good article on manipulating SVG images using javascript can be found here: http://www.sitepoint.com/surviving-the-zombie-apocalypse-manipulating-svg-with-javascript/
Perhaps in your case it would be useful to use a javascript library like svg.js: http://www.svgjs.com/
source share