skip to Main Content

How to cut ".00" from class ".woocommerce-Price-amount" using javascript. There must be a space at the end of the amount.

<div class="elementor-shortcode">
  Free shipping from 
    <span class="woocommerce-Price-amount amount">
      <bdi>100,00&nbsp;
        <span class="woocommerce-Price-currencySymbol">USD</span>           </bdi>
    </span>.
</div>

2

Answers


  1. You can use split for this try this one,

    var word = Hi 00;
    word.split("00");
    
    Login or Signup to reply.
  2. Do you want something like that?

    function myFunction() {
      var x = document.getElementsByTagName("bdi");
      var splittedStr = x[0].innerHTML.replace(',00', '');
      document.getElementById("demo").innerHTML = splittedStr;
    }
    <span class="woocommerce-Price-amount amount">
          <bdi>100,00&nbsp;
            <span class="woocommerce-Price-currencySymbol">USD</span>
            </bdi>
        </span>
        
        <button onclick="myFunction()">Try it</button>
        <p id="demo"></p>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search