The first option is it put your text inside a <span>
, then it will be easily accessible from jQuery. jQuery isn't designed to handle text-only nodes very well.
If you can't change the HTML for whatever reason, then you can use .contents()
and .this.nodeType === 3
(where 3 is a text node).
$('.hulkapps_check_option').contents().each(function() {
if (this.nodeType === 3) {
this.textContent
? this.textContent = this.textContent.replace(/\.00/g, " MX")
: this.innerText = this.innerText.replace(/\.00/g, " MX")
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="hulkapps_check_option">
<input type="checkbox" data-price="4000.00">
Basic banner design (+$ 4000.00)
</label>
You could use .html()
to get the text with the input.
While this works in this scenario - it's too brittle to work in the general case (eg if you wanted to change all "put" with "POST" then you'd get <inPOST type="checkbox"
).
You also lose any events you might have had against any elements inside the label.
var h = $(".hulkapps_check_option").html().replace(/\.00/g, " MXN");
$(".hulkapps_check_option").html(h);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="hulkapps_check_option_before">
<input type="checkbox" data-price="4000.00">
Basic banner design (+$ 4000.00)
</label>
<hr/>
<label class="hulkapps_check_option">
<input type="checkbox" data-price="4000.00">
Basic banner design (+$ 4000.00)
</label>