I am using JQUery in my application .
Inthat i am having a
<label id="label1">Firstname<span class="req"><em> * </em></span></label>
$("#label"+div_id+"").clone();
clone.remove('span');
alert(clone.text());//displaying FirstName*
But i need only Firstname
How to do so in JQUery..Or else is there any method to keep * near Firstname in the label and to retrieve only Firstname instead of span
Working code:
var clone = $("#label1").clone();
$("span",clone).remove();
alert(clone.text());
or
alert( $("#label1").clone().html().replace(/<span.*/,'') );
$('span', clone).remove ()
Here, clone
is the so-called 'context' of the jQuery call, meaning, that jQuery searches spans only inside clone
.
Cheers,
alert($("#label1").text().substring(0,($("#label1").text()).length-3));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.