Changing part of the text of a label

Asked

Viewed 529 times

4

I have the following label created by a plugin

<label>
Buscar:
<input type="search" class="form-control input-sm" placeholder="" aria-controls="Pedidos">
</label>

What I want to do is just change the "Fetch" by something X.

I tried it this way but without success

var Label = $('#Pedidos_filter').find('label').html();
$('#Pedidos_filter').find('label').html(Label.replace('Buscar','x'));

How could it be proceeding?

1 answer

4


jQuery is limited in capturing elements text node, then you have to use the method .contents() and fetch the first/Node element from that array and change the textContent.

Thus:

$('label').contents()[0].textContent = 'x';

jsFiddle: http://jsfiddle.net/ajj854c2/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.