InnerText, InnerHTML, attribute values, value and text in jquery (), HTML (), attribute values, Val () Summary in JS

Source: Internet
Author: User

JS and jquery Get the text, HTML, property values, value methods are not the same.

JS and Jquery,text and InnerText acquisition (<!----> Results)

HTML:<PID= "Test">This is in the paragraph<b>Bold body</b>Text.</P>    <ButtonID= "Btn10">jquery display text</Button>    <!--Text : This is the bold literal in the paragraph.  -    <ButtonID= "Btn11">jquery Display InnerTEXT</Button>    <!--text:undefined.  -    <ButtonID= "Btn12">JS Display InnerTEXT</Button>    <!--text:test -
JS:    $ ("#btn10"). Click (function() {    alert ("text:" + $ ("#test"). Text ());    $ ("#btn11"). Click (function() {    alert ("Text:" + $ ("#test"). InnerText);  });    $ ("#btn12"). Click (function() {    alert ("Text:" + document.getElementById (" Test "). (ID);  });

JS and jquery,html and innerHTML acquisition

HTML:<PID= "Test">This is in the paragraph<b>Bold body</b>Text.</P>    <ButtonID= "Btn20">jquery Display HTML</Button>    <!--HTML: This is the <b> bold </b> text in the paragraph.  -    <ButtonID= "Btn21">jquery Display InnerHTML</Button>    <!--html:undefined -    <ButtonID= "Btn22">JS Display InnerHTML</Button>    <!--HTML: This is the <b> bold </b> text in the paragraph.  -
JS:    $ ("#btn20"). Click (function () {    alert ("HTML:" + $ ("#test"). html ());  });  $ ("#btn21"). Click (function () {    alert ("HTML:" + $ ("#test"). InnerHTML);  });     $ ("#btn22"). Click (function () {    alert ("HTML:" + document.getElementById ("test"). InnerHTML);  });

JS and jquery, attribute value acquisition

HTML:
<ButtonID= "Btn30">JS Gets the attribute value of the ID</Button> <!--id:test - <ButtonID= "Btn31">jquery Gets the property value of the ID</Button> <!--id:test -

JS:     $ ("#btn30"). Click (function () {    alert ("ID:" + document.getElementById ("Test"). id);  });    $ ("#btn31"). Click (function () {    alert ("ID:" + $ ("#test"). attr ("id"));  });

JS and Jquery,value get

HTML:<ButtonID= "Btn40">JS gets the value of the input tag</Button>    <!--value:aaa -    <ButtonID= "Btn41">jquery Gets the value of the input tag (Val ())</Button>    <!--value:aaa -    <ButtonID= "Btn42">jquery Gets the value of the input tag (attr ("value"))</Button>    <!--value:aaa -
JS:     $ ("#btn40"). Click (function () {    alert ("Value:" + document.getElementById ("Test1"). value);  });    $ ("#btn41"). Click (function () {    alert ("Value:" + $ ("#test1"). Val ());    $ ("#btn42"). Click (function () {    alert ("Value:" + $ ("#test1"). attr ("value");  });

Note: the Val () method in jquery can only be used with the value value of the INPUT element to get

InnerText, InnerHTML, attribute values, value and text in jquery (), HTML (), attribute values, Val () Summary in JS

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.