Chapter III Operating JavaScript DOM object
DOM: Document Object Model Document Object Model
DOM Category: Dom core; HTML Dom; Css Dom;
First, according to the hierarchical access node:
Returns the parent node parentNode
childNodes returns the set of child nodes, childNodes [I]
the firstChild Returns the first child node, the most common usage is to access the text node element
lastChild Returns the last child node of
the next node nextSibling
previousSibling a node
childNodes returns the set of child nodes, childNodes [I]
the firstChild Returns the first child node, the most common usage is to access the text node element
lastChild Returns the last child node of
the next node nextSibling
previousSibling a node
Second, resolve browser compatibility issues:
firstElementChild returns the first child node of the most common usage is to access the text of an element node
lastElementChild return to the last child node of
the next nextElementSibling a node
on a node previousElementSibling
lastElementChild return to the last child node of
the next nextElementSibling a node
on a node previousElementSibling
例如:ONext = OParent.nextElementSibling || OParent.nextSibling
Third, the node information:
nodeName: Node Name
nodeValue: node value
nodeType: Node Type
Fourth, the operation node style:
<Script type = "text / JavaScript">
// first way: element style properties .style
function whtmouseover () {
// let Joe Smith Font color green becomes small
. document.getElementById ( "zs") style = .fontSize "15px";
. document.getElementById ( "zs") style.color = "Green";
};
function whtmouseout () {
// let Joe Smith small font color green
document.getElementById ( "zs" ) .style.fontSize = "8px";
document.getElementById ( "ZS") style.backgroundColr = "Pink";.
};
// the second way: the element .className previously created value named .className in style the style list
function lbmouseover () {
the Document. getElementById("zhao").className="zhao";
};
function lbmouseout(){
document.getElementById("zhao").className="zhao";
};
//第三种方式:元素.style.cssText="css属性值"
function llmouseover(){
document.getElementById("ww").style.cssText="color:red;font-size:10px";
}
function llmouseout(){
document.getElementById("ww").style.cssText="color:black;font-size:60px";
}
</script>
五、元素属性:
// first way: element style properties .style
function whtmouseover () {
// let Joe Smith Font color green becomes small
. document.getElementById ( "zs") style = .fontSize "15px";
. document.getElementById ( "zs") style.color = "Green";
};
function whtmouseout () {
// let Joe Smith small font color green
document.getElementById ( "zs" ) .style.fontSize = "8px";
document.getElementById ( "ZS") style.backgroundColr = "Pink";.
};
// the second way: the element .className previously created value named .className in style the style list
function lbmouseover () {
the Document. getElementById("zhao").className="zhao";
};
function lbmouseout(){
document.getElementById("zhao").className="zhao";
};
//第三种方式:元素.style.cssText="css属性值"
function llmouseover(){
document.getElementById("ww").style.cssText="color:red;font-size:10px";
}
function llmouseout(){
document.getElementById("ww").style.cssText="color:black;font-size:60px";
}
</script>
五、元素属性:
Returns the current element offsetLeft its distance from the left edge of the left boundary of the parent element, the read-only attribute
offsetTop Returns the current element border to its distance from the boundary of the parent element, the read-only attribute
offsetHeight height of the return element
offsetWidth return element's width
offsetParent return offset container element, i.e. the recent dynamic positioning of a reference element comprising
returns the vertical scroll position matching elements scrollTop
the scrollLeft return horizontal scroll position matching elements
clientWidth return element visible width
clientHeight visible height of the return element
offsetTop Returns the current element border to its distance from the boundary of the parent element, the read-only attribute
offsetHeight height of the return element
offsetWidth return element's width
offsetParent return offset container element, i.e. the recent dynamic positioning of a reference element comprising
returns the vertical scroll position matching elements scrollTop
the scrollLeft return horizontal scroll position matching elements
clientWidth return element visible width
clientHeight visible height of the return element
Sixth, the element attributes apply:
document.documentElement.scrollTop;
document.documentElement.scrollLeft;
document.documentElement.scrollLeft;
or
document.body.scrollTop;
document.body.scrollLeft;
document.body.scrollLeft;
Seven, making fixed ad:
adver var;
the window.onload = function () {
adver = document.getElementById ( "adver");
}
// the onscroll: the scroll bar to scroll trigger
window.onscroll = function () {
// Get the size of the scroll bar to scroll
var scorlltop = || document.body.scrollTop document.documentElement.scrollTop;
var = scorllleft document.documentElement.scrollLeft || document.body.scrollLeft;
// follower scroll bar elements with changes
adver.style.top = scorlltop + 30 + "px " ;
adver.style.left scorllleft = 10 + + "PX";
}
the window.onload = function () {
adver = document.getElementById ( "adver");
}
// the onscroll: the scroll bar to scroll trigger
window.onscroll = function () {
// Get the size of the scroll bar to scroll
var scorlltop = || document.body.scrollTop document.documentElement.scrollTop;
var = scorllleft document.documentElement.scrollLeft || document.body.scrollLeft;
// follower scroll bar elements with changes
adver.style.top = scorlltop + 30 + "px " ;
adver.style.left scorllleft = 10 + + "PX";
}
DOM: Document Object Model Document Object Model
DOM Category: Dom core; HTML Dom; Css Dom;
First, according to the hierarchical access node:
Returns the parent node parentNode
childNodes returns the set of child nodes, childNodes [I]
the firstChild Returns the first child node, the most common usage is to access the text node element
lastChild Returns the last child node of
the next node nextSibling
previousSibling a node
childNodes returns the set of child nodes, childNodes [I]
the firstChild Returns the first child node, the most common usage is to access the text node element
lastChild Returns the last child node of
the next node nextSibling
previousSibling a node
Second, resolve browser compatibility issues:
firstElementChild returns the first child node of the most common usage is to access the text of an element node
lastElementChild return to the last child node of
the next nextElementSibling a node
on a node previousElementSibling
lastElementChild return to the last child node of
the next nextElementSibling a node
on a node previousElementSibling
例如:ONext = OParent.nextElementSibling || OParent.nextSibling
Third, the node information:
nodeName: Node Name
nodeValue: node value
nodeType: Node Type
Fourth, the operation node style:
<Script type = "text / JavaScript">
// first way: element style properties .style
function whtmouseover () {
// let Joe Smith Font color green becomes small
. document.getElementById ( "zs") style = .fontSize "15px";
. document.getElementById ( "zs") style.color = "Green";
};
function whtmouseout () {
// let Joe Smith small font color green
document.getElementById ( "zs" ) .style.fontSize = "8px";
document.getElementById ( "ZS") style.backgroundColr = "Pink";.
};
// the second way: the element .className previously created value named .className in style the list of styles
function lbmouseover () {
document.getElementById ( "Zhao"). className = " zhao";
};
function lbmouseout(){
document.getElementById("zhao").className="zhao";
};
//第三种方式:元素.style.cssText="css属性值"
function llmouseover(){
document.getElementById("ww").style.cssText="color:red;font-size:10px";
}
function llmouseout(){
document.getElementById("ww").style.cssText="color:black;font-size:60px";
}
</script>
五、元素属性:
// first way: element style properties .style
function whtmouseover () {
// let Joe Smith Font color green becomes small
. document.getElementById ( "zs") style = .fontSize "15px";
. document.getElementById ( "zs") style.color = "Green";
};
function whtmouseout () {
// let Joe Smith small font color green
document.getElementById ( "zs" ) .style.fontSize = "8px";
document.getElementById ( "ZS") style.backgroundColr = "Pink";.
};
// the second way: the element .className previously created value named .className in style the list of styles
function lbmouseover () {
document.getElementById ( "Zhao"). className = " zhao";
};
function lbmouseout(){
document.getElementById("zhao").className="zhao";
};
//第三种方式:元素.style.cssText="css属性值"
function llmouseover(){
document.getElementById("ww").style.cssText="color:red;font-size:10px";
}
function llmouseout(){
document.getElementById("ww").style.cssText="color:black;font-size:60px";
}
</script>
五、元素属性:
Returns the current element offsetLeft its distance from the left edge of the left boundary of the parent element, the read-only attribute
offsetTop Returns the current element border to its distance from the boundary of the parent element, the read-only attribute
offsetHeight height of the return element
offsetWidth return element's width
offsetParent return offset container element, i.e. the recent dynamic positioning of a reference element comprising
returns the vertical scroll position matching elements scrollTop
the scrollLeft return horizontal scroll position matching elements
clientWidth return element visible width
clientHeight visible height of the return element
offsetTop Returns the current element border to its distance from the boundary of the parent element, the read-only attribute
offsetHeight height of the return element
offsetWidth return element's width
offsetParent return offset container element, i.e. the recent dynamic positioning of a reference element comprising
returns the vertical scroll position matching elements scrollTop
the scrollLeft return horizontal scroll position matching elements
clientWidth return element visible width
clientHeight visible height of the return element
Sixth, the element attributes apply:
document.documentElement.scrollTop;
document.documentElement.scrollLeft;
document.documentElement.scrollLeft;
or
document.body.scrollTop;
document.body.scrollLeft;
document.body.scrollLeft;
Seven, making fixed ad:
adver var;
the window.onload = function () {
adver = document.getElementById ( "adver");
}
// the onscroll: the scroll bar to scroll trigger
window.onscroll = function () {
// Get the size of the scroll bar to scroll
var scorlltop = || document.body.scrollTop document.documentElement.scrollTop;
var = scorllleft document.documentElement.scrollLeft || document.body.scrollLeft;
// follower scroll bar elements with changes
adver.style.top = scorlltop + 30 + "px " ;
adver.style.left scorllleft = 10 + + "PX";
}
the window.onload = function () {
adver = document.getElementById ( "adver");
}
// the onscroll: the scroll bar to scroll trigger
window.onscroll = function () {
// Get the size of the scroll bar to scroll
var scorlltop = || document.body.scrollTop document.documentElement.scrollTop;
var = scorllleft document.documentElement.scrollLeft || document.body.scrollLeft;
// follower scroll bar elements with changes
adver.style.top = scorlltop + 30 + "px " ;
adver.style.left scorllleft = 10 + + "PX";
}