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