I have the following markup:
<label class="radio">
<input class="radio" type="radio" name="month_type" value="0" checked="checked">
On day 5
</label>
and i need to change the text from 'On day 5' to 'On day 6'. The selection needs to be upward from input to label.
I have tried:
$("input[name='month_type']").parent().text(''); // the result is an empty string
$("input[name='month_type']").parent().contents().filter(function(){
return this.nodeType === 3; // Uncaught SyntaxError: Unexpected token ILLEGAL
}).remove();
with no luck.
JS:-
$("input[name='month_type']").parent().html(function(){
return $(this).html().replace("On day 5","On day 6");
});
Try this
$("#textchange").click(function(){
$('input[name=month_type]').parent().html('<input class="radio" type="radio" name="month_type" value="0" checked="checked">On day 6');
});
to change the text you'd better try javascript itself instead of jQuery. you might know your label has 2 childNode. the first one is nodType = 1 the last one nodeType = 3. try this and you'll get what you want:
$("input[name='month_type']").parent()[0].lastChild.textContent = "On day 6";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.