InnerHTML outerhtml innerText Value Difference

Source: Internet
Author: User

Defined
    • innerHTML: 属性设置或返回表格行的开始和结束标签之间的 HTML。(也就数说,用innerHTML的元素必须是标签对的形式,也就是input啥都输不出来)
    • outerHTML: 设置或获取对象及其内容的 HTML 形式。(标签对,input输出本身)
    • innerText: 设置或获取位于对象起始和结束标签内的文本。(标签对,input啥也输不出来)
    • value 这个用的地方比较多,这里仅以input中的value为例。就是input的值。(标签对,输出undefined)
Code
1 <spanID= "outer"value= "This is outer">2     <spanID= "Mid"value= "This is mid">3         <spanID= "inner"value= "This is inner">Text</span>4         <inputtype= "text"ID= "Input"value= "This is the content of input"/>5     </span>6 </span>
1 varouter = document.getElementById (' outer '));2 varMid = document.getElementById (' Mid ');3 varInner = document.getElementById (' inner '));4 varinput = document.getElementById (' input ');5 6Console.log (' Outer's value is ' +outer.value);7Console.log (' Outer's innerhtml is ' +outer.innerhtml);8Console.log (' Outer's outerhtml is ' +outer.outerhtml);9Console.log (' Outer's innertext is ' +outer.innertext);Ten  OneConsole.log (' Mid ' value is ' + 'mid.value); AConsole.log (' Mid's innerhtml is ' +mid.innerhtml); -Console.log (' Mid's outerhtml is ' +mid.outerhtml); -Console.log (' Mid's innertext is ' +mid.innertext); the  -Console.log (' Inner's value is ' +inner.value); -Console.log (' Inner's innerhtml is ' +inner.innerhtml); -Console.log (' Inner's outerhtml is ' +inner.outerhtml); +Console.log (' Inner's innertext is ' +inner.innertext); -  +Console.log (' input ' value is ' + 'input.value); AConsole.log (' input ' innerhtml is ' +input.innerhtml); atConsole.log (' input ' outerhtml is ' +input.outerhtml); -Console.log (' input ' innerText is ' + input.innertext ');
Results

InnerHTML outerhtml innerText Value Difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.