When we need to dynamically generate DOM objects, we will use the createElement method to create them. However, in IE and Firefox, The createElement method is different.
In IE, you can use either of the following methods to create an element:
1. document. createElement ('table ')
2. document. createElement ('<table border = "0"> ')
In Firefox, only:
Document. createElement ('table ')
In addition, if you add attributes and events, you must use the setAttribute method.
Example:
Copy codeThe Code is as follows:
If ($. browser. msie ){
Var rowHtml = '<span class = "ellipsis" onclick = "';
RowHtml + = '_ showNotice (/'';
RowHtml + = id
RowHtml + = '/',/'';
RowHtml + = titlePre;
RowHtml + = '/')"';
RowHtml + = "> ";
RowHtml + = "</span> ";
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 {
}