Reputation: 373
I have a checkout page on a site that generates a shipping message. I need to change the text of that shipping message.
Here is the path to the element needing changed:
#order_review > table > tfoot > tr.shipping > td > p
Here is the approach I'd like to take (correct me if a better one), but I need help drilling down to the right element:
var oldstring = "Enter your shipping information above to show shipping options."
var changeit = document.getElementById("order_review");
changeit.oldstring.replace("Enter your shipping information above to show shipping options.", "Enter your full address to verify free delivery.");
Upvotes: 1
Views: 55
Reputation: 309
var qs = document.getElementById("order_review");
qs.querySelector("table > tfoot > tr.shipping > td > p").innerHTML = "Enter your full address to verify free delivery.";
<div id="order_review">
<table>
<tfoot>
<tr class="shipping">
<td>
<p>Enter your shipping information above to show shipping options.</p>
</td>
</tr>
</tfoot>
</table>
</div>
Upvotes: 1
Reputation: 21
I like to use textContent
when updating text on the DOM:
let el = document.querySelector("#order_review > table > tfoot > tr.shipping > td > p");
el.textContent = "Enter your full address to verify free delivery.";
Upvotes: 1
Reputation: 25351
You can use the querySelector
method as Andereas mentioned in the comments. You don't need to use replace
, simply assign the new text to innerHTML
or textContent
:
var changeit = document.querySelector("#order_review > table > tfoot > tr.shipping > td > p");
changeit.textContent = "Enter your full address to verify free delivery.";
If you want to keep the reference to the order_review
and drill down from there, you can do this:
var changeit = document.getElementById("order_review");
changeit.querySelector("table > tfoot > tr.shipping > td > p").textContent = "Enter your full address to verify free delivery.";
Upvotes: 1