Current location - Quotes Website - Signature design - How does jquery get the content in the label tag?
How does jquery get the content in the label tag?

jquery provides three methods to obtain content: text(), html() and val(), of which the first two can be used to solve this problem: $("label#userid").text( );//?First choice, get the text of the label

$("label#userid").html();//?It can also be achieved, get all the html tags in the label label, generally change There is text in the label label, so it is equivalent to the above method

The following is an example demonstration: use the above two methods to obtain the content of the label label, pay attention to the difference in the final results

Create Html element

Click the button to get the content in the label:

Enter user name

< p>

Set css style div.box{width:300px; padding:20px;margin:20px;border:4px?dashed?#ccc;}

div.box?span{color:#999;font-style:italic;}

div.content{width:250px;margin:10px?0;padding:20px;border:2px?solid?#ff6666;}

h3{display:inline-block;}

input[type='button']{height:30px;margin:10px;padding:5px?10px;}

Write jquery code $(function(){

$( "input:button.btn1").click(function()?{

alert($("label#userid").text());

});< /p>

$("input:button.btn2").click(function()?{

alert($("label#userid").html());

});

})

Observe the effect

Use the text() method to get the content in the tag

Use The html() method will obtain the elements within the tag (including Html tags)

Related articles