Sometimes, it is useful to create DOM elements as jQuery objects for use as selectors and context.
The following works in both IE7,IE8 and all other browsers using jQuery 1.6.2/3 – but note that document.createElement is used to make this work.in IE7 and IE8.
jQuery('body').append('<div id="basic-render-test"> </div>');
var new_object = {};
new_object.wrapper = '<span id="adfasdfasdfwersadfas3rs">';
//alert(typeof new_object.wrapper);
if (jQuery.browser.msie && jQuery.browser.version <= 8.0){
new_object.el = document.createElement(new_object.wrapper);
} else {
new_object.el = jQuery(new_object.wrapper);
}
new_object.render_into = "#basic-render-test";
jQuery(new_object.render_into).append( new_object.el );
some_html = '<DIV id="type-m" class="translate"> HELLO IE</DIV>';
jQuery(new_object.el).html( some_html );
The declared DOM type is HTML 5
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
You need to provide an actual valid html code for it to be created properly. In your exemple, your span tag is not closed, which result in an invalid code at evaluation in IE while other browsers tend to fix it automagically.
Replace
With
This exemple runs perfectly on both IE 7 and 8