Home > Web Front-end > JS Tutorial > Sharing of 7 different syntaxes in JavaScript between IE and Firefox_javascript skills

Sharing of 7 different syntaxes in JavaScript between IE and Firefox_javascript skills

WBOY
Release: 2016-05-16 17:59:58
Original
1109 people have browsed it

In this article, the author introduces 7 different JavaScript syntaxes in IE and Firefox.

javascript ie firefox
1. CSS "float" value

The most basic syntax for accessing a given CSS value is: object.style.property, using camelCase to replace the value with connectors , for example, to access the background-color value of a

with the ID "header", we use the following syntax:

document.getElementById("header").style.backgroundColor= "#ccc" ;

But since the word "float" is a JavaScript reserved word, we cannot use object.style.float to access it. Here, we can do this in two browsers:

Write this in IE:

Copy code The code is as follows:

document.getElementById(" header").style.styleFloat = "left";

Write this in Firefox:
Copy code The code is as follows:

document.getElementById("header").style.cssFloat = "left";

2. The estimated style of the element
JavaScript can use the object.style.property syntax to easily access and modify a CSS style externally, but the limitation is that these syntaxes can only take out already set inline styles or styles set directly by JavaScript. It cannot access an external style sheet. To access the "imputed" style of an element we can use the following code:

In IE write this:
Copy code The code is as follows:

var myObject = document.getElementById("header");
var myStyle = myObject.currentStyle.backgroundColor;

In In Firefox, write this:
Copy code The code is as follows:

var myObject = document.getElementById( "header");
var myComputedStyle = document.defaultView.getComputedStyle(myObject, null);
var myStyle = myComputedStyle.backgroundColor;

3. Access the element's "class"
Like "float", "class" is a reserved word of JavaScript. In these two browsers, we use the following syntax to access "class".

Write this in IE:
Copy the code The code is as follows:

var myObject = document.getElementById("header");
var myAttribute = myObject.getAttribute("className");

Write this in Firefox:
Copy code The code is as follows:

var myObject = document.getElementById("header");
var myAttribute = myObject. getAttribute("class");

This syntax would also apply using the setAttribute method.

4. Access the
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