tags:

views:

356

answers:

3

Hi,

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

A: 
$('span', clone).remove ()

Here, clone is the so-called 'context' of the jQuery call, meaning, that jQuery searches spans only inside clone.

Cheers,

Boldewyn
+1  A: 

Working code:

var clone = $("#label1").clone();                                                       
$("span",clone).remove();
alert(clone.text());

or

alert(  $("#label1").clone().html().replace(/<span.*/,'')  );
Evgeny
A: 

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

Nrj