Reputation: 1883
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.
Upvotes: 0
Views: 87
Reputation: 12961
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";
Upvotes: 0
Reputation: 549
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');
});
Upvotes: 1
Reputation: 97672
Try
$("input[name='month_type']")[0].nextSibling.data = ' On day 6';
Upvotes: 0
Reputation: 9612
JS:-
$("input[name='month_type']").parent().html(function(){
return $(this).html().replace("On day 5","On day 6");
});
Upvotes: 1