Use Jquery to swap out text without the need for a separate update button

Looking to replace "Gastos de envío: " with "Shipping costs" on the English page.

I currently have this jQuery code (which is working), but it only replaces the text the first time you visit the page. If you update the shipping costs, the jquery does not replace the text again.

Is there a way to automatically replace the text without needing an update button?:

jQuery(function ($) {

  jQuery('label[for^="shipping_method_0').contents().filter(function() { 
    return this.nodeType === 3 && jQuery.trim(this.textContent).length;
  })
  .replaceWith('Shipping\ costs: ');

});

https://i.sstatic.net/ZSJtC.png https://i.sstatic.net/qk5sQ.png

Update: Not permitted to alter the HTML code

Answer №1

If you're looking for a way to customize your shipping costs display, you can follow this example:

<label>
    Shipping Costs
    <span class="woocommerce-Price....">120.87 €</span>
    <small>(incl. VAT)</small>
</label>
<button id="YourBTN">SUBMIT</button>

And if you want to change the text using JavaScript, here's how you can do it:

<script>
    $(document).ready(function(){
        $("#YourBTN").click(function(){
            $("label").each(function() {
              var text = $(this).text();
                text = text.replace("Shipping Costs", "New Shipping Label");
                $(this).text(text);
          });
        });
    });
</script>

Hope this helps!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing my Bootstrap carousel to only slide once?

I'm currently working on integrating a Bootstrap Carousel into my website, but I've encountered an issue where it moves only once and then becomes unresponsive. After checking the file order, I couldn't find any issues there. So, I'm qu ...

Avoiding cheating in a JavaScript game

I am in the process of creating a JavaScript/JQuery game that resembles a classic brick breaker. The game includes features such as scoring, levels, and more. I have plans to add a leaderboard where users can submit their final scores. However, my concer ...

The conceal feature doesn't appear to be functioning properly on jQuery Mobile

I am facing an issue with a small mobile app built using jQuery Mobile. Within a div, I have three buttons and other content. My goal is to hide these three buttons if the user's device is running on Windows (WP). The buttons are defined as follows: ...

AJAX call using jQuery not returning the expected callback result

My goal is rather straightforward: I want to store the object retrieved from Instagram's API in a variable so that I can manipulate it as needed. Here is my current progress: $(document).ready(function() { // declare variable var instagram_infos; fu ...

I'm confused about what I did wrong with Node.js. The server.js is up and running, but I'm unable to view the

I have made some progress so far and I am currently running this code on Putty. var http = require('http'); var fs = require('fs'); const PORT = 8080; http.createServer(function(request, response) { var url = request.url; switc ...

Utilizing the Power of ChartJs

I am currently in the process of developing a web application that will provide users with the ability to compare the number of calories they burn during exercise with the amount they consume in a meal. To achieve this goal, I have chosen to utilize ChartJ ...

Change the text inside a container without losing any associated event listeners using JavaScript or jQuery

Here is the HTML code: <div id="div001"> This is ${Row.1}. <p>${Row.2} explain something else.</p> <p>${Row.3} welcome you. <span>${Hello.World}, this is a new world.</span></p> </div> My objective is ...

Updating multiple divs with the same class using different values returned from an AJAX success callback in jQuery

Consider a scenario where there is a group of div elements like <div class="size"></div> <div class="size"></div> After an AJAX post request successfully returns the following data. $.each (data, function (bb) { // data is return ...

Passing a JSON object to a different page using jQuery

I'm currently facing a challenge with sending JSON data (demographics) to a new page within the same directory when a user clicks on a marker that I've placed on a Google map on my website. I am using the jquery-ui-map plugin, and while the marke ...

Instructions on setting div opacity when Overflow is set to visibleExplanation on setting opacity for div with Overflow

In my HTML code, I have a div element and an image tag stacked one on top of the other. The div is smaller than the image. I have set the overflow property to visible for the div. My query is, when I add an image to the image tag, the content that overflow ...

Tips for showing a form's help text when manually rendering fields in Django forms?

In my Forms.py file, I have the following code snippet: class CustomerForm(forms.Form): name = forms.CharField(max_length=255,required=True,validators=[alphaonly],help_text="Enter your name") I am attempting to render it in an HTML format like ...

Differences between using tables and divs for form layouts

After searching online for examples of form implementations using DIVs, I noticed that most were simple one-column forms. However, my forms are more complex, like the one shown in this image: Although I can easily create these forms using tables, I encoun ...

Align the text to the center within the Paper component using React and Material-ui

I've been struggling to center text inside a paper component in Material UI, and nothing seems to be working. I attempted using display:flex in the parent component with align-items:center in the child component. I also tried adding padding:5px for eq ...

The themes showcased in the Bespoke.js documentation and demo exhibit unique designs

Recently, I stumbled upon an incredible HTML5 framework for presentations. For more information, you can check out the documentation here. You can also view a demo of the framework by visiting this link. However, I was disappointed to find that the caro ...

How can I display base64 image data in a new window without triggering a block?

Currently experiencing challenges with Javascript. Utilizing html2canvas to convert a div to a canvas and then using .toDataURL to convert the canvas to a base64 data stream. Attempting to open base64 image data in a new window, but facing blocks from va ...

Resize images within a button using table cell size in Bootstrap

I am looking to create a row of buttons within a table, where each button is represented by an image and has a transparent border/background. To achieve this, I placed each button in one of the 10 remaining cells of a table using <td class="col-sm ...

Creating two interactive animations utilizing a combination of CSS and Javascript, triggered by the click event on

Looking to incorporate two unique CSS animations into my project. Utilizing two buttons and one object, I want the first animation to trigger upon clicking the first button. I understand how to handle one button and one animation, but am unsure how to man ...

What's the deal with jQuery and Intraweb?

Does anyone know how to create a jQuery notification or popup calendar in Intraweb? I would really appreciate a simple example. If possible, I'd love to see a version using Dojo as well. ...

I'm experiencing issues with my code involving HTML, CSS, and jQuery

Recently, I started learning about jQuery and came across a tutorial on creating a sticky nav bar. However, something went wrong during the implementation and now I don't know how to fix it! In my Script file, I have written code that should run on l ...

Transferring an HTML file to a destination stream

Currently, I'm in the process of constructing a proxy server. One of the tasks I'm tackling involves blocking specific URLs. I have developed a simple HTML page that is supposed to display whenever a blocked URL is requested, but unfortunately, ...