Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:15:30
Original
1080 people have browsed it

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{

}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template