Input via ID assignment js jquery innerhtml and outerhtml difference

Source: Internet
Author: User
Tags html form jquery innerhtml

1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "Utf-8" />5         <title>Input</title>6             <Scripttype= "Text/javascript"src= "Js/jquery-1.8.1.min.js" ></Script>    7     </Head>8     <Body>9     <Script>Ten     functionchange_jq () { One  A         //JQ Gets the input value -         varUser_val=$('#user'). Val (); -         //JQ assignment to input the         $('#display_val'). Val (user_val); -         //modifiable ID val, etc. -         $("#display_val2"). attr ("value", user_val); -     } +      -     functionChange_js () { +         //JS Get A         varBook_name=document.getElementById (" Book"). Value; at         //JS Assign value - document.getElementById ("Book_val"). Value=Book_name; -     } -      -     functionGet_div_val () { -         varHTML=document.getElementById ("Div1"); in Console.log ('InnerHTML:'+html.innerhtml);//InnerHTML: This is a div<span> this is a span</span> - Console.log ('outerhtml:'+html.outerhtml);//outerhtml:<div id= "Div1" > It's a div<span> it's a span</span></div> to Console.log ('InnerText:'+html.innertext);//InnerText: This is a div which is a span + Console.log ('outertext:'+html.outertext);//Outertext: This is a div which is a span -     } the     </Script> *     <H3>Input</H3> $Input content:<inputID= "User"placeholder= "Please enter ..."onchange= "CHANGE_JQ ();"type= "text">Panax NotoginsengJQ assigns a value of $ ("#id"). Val (val):<inputID= "Display_val"type= "text" > -JQ assigns a value of $ ("#id"). attr ("value", Val):<inputID= "Display_val2"type= "text" > the        +      <BR> A      <BR> theInput:<inputID= "book"placeholder= "Please enter ..."onchange= "Change_js ();"type= "text"/> +JS Assignment:<inputID= "Book_val"type= "text" />       -      <HR/> $      <H3>Div</H3> $      <inputtype= "button"onclick= "Get_div_val ()"value= "Get div content"/> -      <DivID= "Div1">This is a div<span>This is a span</span></Div> -      <P>  theInnerHTML Sets or gets the HTML that is located within the start and end tags of the object<BR/> -outerHTML Sets or gets the HTML form of an object and its contents<BR/>WuyiInnerText set or get text that is within the start and end tags of an object<BR/> theOutertext set (including tags) or get (excluding tags) the text of an object<BR/> -      </P> Wu         -     </Body> About </HTML>

Input via ID assignment js jquery innerhtml and outerhtml 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.