Definition and Usage lastChild..
The lastChild property returns the last child node of the specified node, as a Node object.
The difference between this property and lastElementChild, is that lastChild returns the last child node as an element node, a text node or a comment node (depending on which one's last), while lastElementChild returns the last child node as an element node (ignores text and comment nodes).
Note: Whitespace inside elements is considered as text, and text is considered as nodes (See "More Examples").
This property is read-only.
Tip: Use the element.childNodes property to return any child node of a specified node.
Tip: To return the first child node of a specified node, use the firstChild property.
Return Value:A Node object, representing the last child of a node, or null if there are no child nodes.
Syntax : node.lastChild
Definition and Usage lastElementChild..
The lastElementChild property returns the last child element of the specified element.
The difference between this property and lastChild, is that lastChild returns the last child node as an element node, a text node or a comment node (depending on which one's last), while lastElementChild returns the last child node as an element node (ignores text and comment nodes).
This property is read-only.
Tip: Use the children property to return any child element of a specified element.
Tip: To return the first child element of a specified element, use the firstElementChild property.
Return Value:A Node object, representing the last child element of an element, or null if there are no child elements.
Syntax : element.lastElementChild
Differents way how to declare lastChild & lastElementChild Property in program.
CODING:The lastChild property returns the last child node of the specified node, as a Node object.
The difference between this property and lastElementChild, is that lastChild returns the last child node as an element node, a text node or a comment node (depending on which one's last), while lastElementChild returns the last child node as an element node (ignores text and comment nodes).
Note: Whitespace inside elements is considered as text, and text is considered as nodes (See "More Examples").
This property is read-only.
Tip: Use the element.childNodes property to return any child node of a specified node.
Tip: To return the first child node of a specified node, use the firstChild property.
Return Value:A Node object, representing the last child of a node, or null if there are no child nodes.
Syntax : node.lastChild
Definition and Usage lastElementChild..
The lastElementChild property returns the last child element of the specified element.
The difference between this property and lastChild, is that lastChild returns the last child node as an element node, a text node or a comment node (depending on which one's last), while lastElementChild returns the last child node as an element node (ignores text and comment nodes).
This property is read-only.
Tip: Use the children property to return any child element of a specified element.
Tip: To return the first child element of a specified element, use the firstElementChild property.
Return Value:A Node object, representing the last child element of an element, or null if there are no child elements.
Syntax : element.lastElementChild
Differents way how to declare lastChild & lastElementChild Property in program.
<!DOCTYPE html>
<html>
<body>
<h4 id="h4">Soft Languages:</h4>
<ul id="lan"><li>C++</li><li>JAVA</li><li>PYTHON</li></ul>
<button onclick="con()">Last Contant</button>
<button onclick="nod()">Last Node Name</button>
<h4 id="h42">Web Languages:</h4>
<select id="Select" size="4"><option>HTML</option><option>CSS</option><option>JAVA SCRIPT</option><option>XML</option></select><br><br>
<button onclick="con2()">Last Contant</button>
<button onclick="nod2()">Last Node Name</button>
<p><strong>Note:</strong> Whitespace inside elements is considered as text, and text is considered as nodes.If you add whitespace before the first LI element, the result will be "undefined".</p>
<script>
function con() {
var x = document.getElementById("lan").lastChild.innerHTML;
document.getElementById("h4").innerHTML += x;
}
function nod() {
var y = document.getElementById("lan").lastChild.nodeName;
document.getElementById("h4").innerHTML += y;
}
function con2() {
var a = document.getElementById("Select").lastChild;
document.getElementById("h42").innerHTML += a.text;
}
function nod2() {
var b = document.getElementById("Select").lastChild;
document.getElementById("h42").innerHTML += b.nodeName;
}
</script>
</body>
</html>
<html>
<body>
<h4 id="h4">Soft Languages:</h4>
<ul id="lan"><li>C++</li><li>JAVA</li><li>PYTHON</li></ul>
<button onclick="con()">Last Contant</button>
<button onclick="nod()">Last Node Name</button>
<h4 id="h42">Web Languages:</h4>
<select id="Select" size="4"><option>HTML</option><option>CSS</option><option>JAVA SCRIPT</option><option>XML</option></select><br><br>
<button onclick="con2()">Last Contant</button>
<button onclick="nod2()">Last Node Name</button>
<p><strong>Note:</strong> Whitespace inside elements is considered as text, and text is considered as nodes.If you add whitespace before the first LI element, the result will be "undefined".</p>
<script>
function con() {
var x = document.getElementById("lan").lastChild.innerHTML;
document.getElementById("h4").innerHTML += x;
}
function nod() {
var y = document.getElementById("lan").lastChild.nodeName;
document.getElementById("h4").innerHTML += y;
}
function con2() {
var a = document.getElementById("Select").lastChild;
document.getElementById("h42").innerHTML += a.text;
}
function nod2() {
var b = document.getElementById("Select").lastChild;
document.getElementById("h42").innerHTML += b.nodeName;
}
</script>
</body>
</html>
Comments
Post a Comment