简体   繁体   English

从JQuery中的标签中删除*

[英]Remove * from label in JQuery

I am using JQUery in my application . 我在我的应用程序中使用JQUery。

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 如何在JQUery中执行此操作。否则,是否有任何方法可以将*保留在标签中的名字附近,并且仅检索名字而不是范围

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 . 在这里, clone是jQuery调用的所谓“上下文”,即jQuery仅在clone内部搜索。

Cheers, 干杯,

alert($("#label1").text().substring(0,($("#label1").text()).length-3));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM