Home  >  Article  >  Web Front-end  >  Use jQuery to solve the difference between createElement methods under IE and FireFox_jquery

Use jQuery to solve the difference between createElement methods under IE and FireFox_jquery

WBOY
WBOYOriginal
2016-05-16 17:15:301047browse

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:

Copy code The code is as follows:

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{

}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn