javascript : Object.isDomElement
javascript : Object.isDomElement
Target:
Applicable with any javascript Object Variable that holds DOM Element .
Description :
When an object holds an html domElement then it return true otherwise undefined. basically it is defined in DomElement prototype. Many time in programming we face a problem that an object variable holds DomElement or other object structure then it help us. Before writing the code of DomElement manipulation we can check whether a variable holds DomElement or not.
Note: It is an property of DomElement that is defined in DomElement Prototype.
It is useful to check an object variable is DomElement or any other type.
When we check the typeof(object_variable) it return 'object' not 'DomElement/Node'.
Syntax:
Object.isDomElement
return true when object hold's DomElement otherwise undefined
Usase:
- var obj = document.querySelector('div')
if(obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object holds DomElement". - var obj = document.createElement('p')
if(obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object holds DomElement". - var obj = {}
if(obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object is not DomElement". - var obj = []
if(obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object is not DomElement". - var obj = document.querySelectorAll('li')
if(obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object is not DomElement". - var obj = document.getElementById('firstDiv');
if(obj && obj.isDomElement){
console.log('Object holds DomElement');
}
else{
console.log('Object is not DomElement');
}
It return "Object holds DomElement".
Download MYJS.js
Comments
Post a Comment