
The relationship between setAttribute and different versions of ie in javascript
Browser versions are constantly being updated and upgraded, and some javascript methods that are not supported by lower browsers are also supported in higher versions. This is why some javascript code can be executed normally in some high-level browsers, but the error is reported in the low-level browsers or compatibility mode of high-level browsers.
Take javascript to set html element attribute. The setAttribute method is not supported by some low-level Internet Explorer browsers, and other methods must be used, otherwise an error will be reported.
1. Ie version supporting setAttribute method
The setAttribute method is only supported in versions above ie8, neither ie6 nor ie7. The following code can be executed normally in versions above ie8, ie6 and ie7 report errors:
<div id="pageid"></div>
var p = document.getElementById("pageid");
p.setAttribute("style", "width:90%");
The above code uses a percentage to determine the width of the webpage, mainly using the setAttribute() method of javascript to set the style attribute of div to determine the width.
2. Use javascript to set the width of the html element for ie6 and ie7
Before setAttribute() came out, how did javascript set the width of html elements? The web front-end setter who is familiar with ie6 must be familiar with "obj.style.width =", which was used to set html element attributes. Since this method supports the lower version of ie, the higher version of ie is also supported, because the program has the habit of backward compatibility. The specific setting code is as follows:
<div id="pageid"></div>
var p = document.getElementById("pageid");
p.style.width = "88%";
-
Related Reading
- Javascript multidimensional array (create, add and r
- Remove text after clicking in the textbox and then d
- Javascript get referrer url(previous page url), curr
- Javascript get current url, domain from url, relativ
- Javascript convert hex to decimal, binary to hex, oc
- Javascript delay loading images to improve web page
- Remove html element javascript by their parent or cl
- Javascript get all input elements in form and all im
- Javascript sets the element height that cannot be au
- Javascript create element(div,li,img,span) dynamical
- Javascript click child element to add onclick to par
- Mod operator and rounding off numbers in javascript