javascript : DomElement .html(html)

 

javascript : DomElement .html(html)


Target:

Applicable with any DOM element having attribute innerHTML.

  • getElementById
  • getElementsByTagName
  • getElementsByClassName
  • getElementsByName
  • querySelector
  • querySelectorAll

In case of DOM NodeList first Node Element is processed for get/set.


Description :

get/set innerHTML of DOM element. if html is passed then it set the innerHTML and return element itself, otherwise return innerHTML of element.


Note: after setting the innerHTML of element it return the element itself.


Syntax:

DOMElement.html('html')

DOMNodeList.html('html')

HTMLCollection.html('html')


Usase:

  1. document.getElementById('firstDiv').html("welcome")
    it sets the innerHTML of div having id firstDiv with html "welcome" and return firstDiv element
  2. document.querySelector('#firstDiv').html("welcome")
    it sets the innerHTML of div having id firstDiv with innerHTML "welcome" and return firstDiv element
  3. document.getElementById('firstDiv').html()
    it returns the innerHTML of firstDiv, that is "welcome"
  4. document.querySelector('#firstDiv').html()
    it returns the innerHTML of firstDiv, that is "welcome"
  5. document.getElementById('firstDiv').html("welcome").html()
    it set the innerHTML of firstDiv with "welcome" and then get the innerHTML of firstDiv, that is "welcome"
  6. document.querySelectorAll('div').html("welcome")
    it sets the first div's innerHTML with html "welcome" and return divNodeList
  7. document.querySelectorAll('div').html()
    it returns the innerHTML of first div's, that is "welcome"



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()