The jquery text () method retrieves the text in the label, jquerytext

Source: Internet
Author: User

The jquery text () method retrieves the text in the label, jquerytext

<Span id = "236" class = "active" type = "teacher" ww = "nn"> <input type = "checkbox" onclick = "event. cancelBubble = true; "> Liu 4 </span>

Obtain the text "Liu 4"
Get id

$("input:checked",".simpleTree").each(function(){var currentNode = $(this).parent(); var isfolder = currentNode.text(); var id=currentNode.attr("id")alert(isfolder); });

Jquery () text () Usage

. Text () is used to read the plain text content of an element, including its child element.

It is easy to get the content in tag a, just locate it:
$ (". Demo p a"). text ();

However, it is difficult to get p's text, and it cannot be done in one place.
$ P = $ (". demo p"). clone ();
$ P. children (). remove (). end (). text ();

How does jQuery obtain the text content of an element, such as this simple example?

First, your var x = document. getElementsByTagName ("p"); after this statement is executed, x is a dom array instead of a jquery object. Y references an element in the dom array. You can obtain the text value by obtaining the value of y. innerHTML.
Test:
$ (Document). ready (function (){
Var x = document. getElementsByTagName ("p ");
Var y = x [0];
Alert (y. innerHTML); // obtain the text in the first p element tag
});

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.