Home > Article > Web Front-end > Use jQuery to solve the difference between createElement methods under IE and FireFox_jquery
When we need to dynamically generate a DOM object, we will use the createElement method to create it. But under IE and Firefox, the createElement method is different.
In IE, you can create an element in two ways:
1. document.createElement('table')
2. document.createElement(' And Firefox only supports: document.createElement('table') At the same time, if you add attributes and events, you need to use the setAttribute method Example:')
if ($.browser.msie){
var rowHtml = ' rowHtml = ">";
rowHtml = "" ;
row = $(document.createElement(rowHtml)).text(data.Title);
}else if($.browser.mozilla){
var el = document.createElement( "span");
el.setAttribute("onclick","_showNotice(/'" id "/',/'" titlePre "/')");
row = $(el) .text(data.Title);
}else if($.browser.safari){
}else if($.browser.opera){
}else{
}
Related articles
See more