How can I change text Add Your Image
to Change Your Image
.
<label class="control-label col-md-offset-4 col-md-4 btn green feedbackImg" style="text-align:center;">
Add Your Image
<input type="file" name="data[Feedback][img]" class="form-control hide single_img_btn" id="1" style="display: none;">
</label>
$('.feedbackImg').text('Change Your Image');
But it changed the label
as follows :
<label class="control-label col-md-offset-4 col-md-4 btn green feedbackImg" style="text-align:center;">
Add Your Image
</label>
That means it remove input tag also. How can I keep all same except the text only?
Use the innerHTML property to change the text inside the label. The innerHTML property sets or returns the HTML content of an element.
replaceWith() method. With the jQuery replaceWith() method, we can replace each element in the set of matched elements with the provided new content and return the set of elements that were removed.
If you can change your HTML then simply wrap the text you want to change in a span
to make it easier to select:
<label class="control-label col-md-offset-4 col-md-4 btn green feedbackImg" style="text-align:center;">
<span>Add Your Image</span>
<input type="file" name="data[Feedback][img]" class="form-control hide single_img_btn" id="1" style="display: none;">
</label>
$('.feedbackImg span').text('Change Your Image');
If you can't change the HTML, then you would need to amend your JS code to retreive and amend the textNode itself:
$('.feedbackImg').contents().first()[0].textContent = 'Change Your Image';
You need to update the textNode
contents()
- for getting all nodes including text and commentseq()
- get first element , which is textNode(label)replaceWith()
- update the text content with new textCODE:
$('.feedbackImg').contents().eq(0).replaceWith('Change Your Image');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label class="control-label col-md-offset-4 col-md-4 btn green feedbackImg" style="text-align:center;">
Add Your Image
<input type="file" name="data[Feedback][img]" class="form-control hide single_img_btn" id="1" style="display: none;">
</label>
OR
$('.feedbackImg').contents()[0].nodeValue = 'Change Your Image';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label class="control-label col-md-offset-4 col-md-4 btn green feedbackImg" style="text-align:center;">
Add Your Image
<input type="file" name="data[Feedback][img]" class="form-control hide single_img_btn" id="1" style="display: none;">
</label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With