你的位置:首页 > 软件开发 > 网页设计 > innerHTML/outerHTML; innerText/outerText; textContent

innerHTML/outerHTML; innerText/outerText; textContent

发布时间:2016-05-12 11:00:07
innerHTML v.s. outerHTMLElement.innerHTML  Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML  Functionality  G ...

innerHTML v.s. outerHTML

  • Element.innerHTML
    •   Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
    •   Functionality
      •   Get serialized HTML code describing its descendants.
      •   Set : Remove all the children, parse the content string and assign the resulting nodes as the children of the element. 
  • Element.outerHTML
    •   Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML
    •   Functionality
      •   Get serialized HTML fragment describling the element and its descendants.
      •   Set : Replace the element with the nodes generated by parsing the content string with parent of the element as the context node for the fragment parsing algorithm.
    •   NOTE
      •   If element has no parent element, set outerHTML will throw DOMException.
        •   e.g. [Chrome Dev Console]  document.documentElement.outerHTML='a';   Uncaught DOMException: Failed to set the 'outerHTML' property on 'Element': This element's parent is of type '#document', which is not an element node.
      •   Considering below code.

        原标题:innerHTML/outerHTML; innerText/outerText; textContent

        关键词:HTML

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。