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
});