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:

  1. 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".
  2. 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".
  3. var obj = {}
    if(obj.isDomElement){
         console.log('Object holds DomElement');
    }
    else{
         console.log('Object is not DomElement');
    }
    It return "Object is not DomElement".
  4. var obj = []
    if(obj.isDomElement){
         console.log('Object holds DomElement');
    }
    else{
         console.log('Object is not DomElement');
    }
    It return "Object is not DomElement".
  5. 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".
  6. 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

MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type. 

Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.

Comments

Popular posts from this blog

javascript : String.right

javascript : String.left

javascript : .nextAll()