Change part of the text of a label

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 "Search" for something X.

I tried it the following way but without success

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

How could I be doing this?

    
asked by anonymous 06.03.2015 / 14:55

1 answer

4

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

So:

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

jsFiddle: link

    
06.03.2015 / 15:00