I need to replace just the text 'Yes, I want to receive News, Discounts and Promotions'
to my custom text
.
From this:
<p id="woo_ml_subscribe_field">
<label class="checkbox ">
<input type="checkbox" name="woo_ml_subscribe" id="woo_ml_subscribe" value="1" class="input-checkbox " checked="checked"> Yes, I want to receive News, Discounts and Promotions
</label>
</p>
To this:
<p id="woo_ml_subscribe_field">
<label class="checkbox ">
<input type="checkbox" name="woo_ml_subscribe" id="woo_ml_subscribe" value="1" class="input-checkbox " checked="checked"> my custom text
</label>
</p>
I tried with this code but it delete ‘input’ element which is inside the ‘p’ element. The input should remain after the replacement.
var content = $("#woo_ml_subscribe_field label").text().replace(' Yes, I want to receive News, Discounts and Promotions','my custom text')
$("#woo_ml_subscribe_field label").html(content);
2
Answers
you can find the not empty TEXT_NODE and replace, like:
Instead of going for a complex jQuery code, you can put the text inside an HTML element like
<span>
and then you can easily manipulate them.Working snippet: