S
S
SP2020-05-07 12:42:31
JavaScript
SP, 2020-05-07 12:42:31

How to set a condition (replacing the html block) if the price is 0?

<span class="price"><span class="Price-amount amount">0.00&nbsp;<span class="Price-currencySymbol"></span></span></span>
<info></info>

<span class="price"><span class="Price-amount amount">10.50&nbsp;<span class="Price-currencySymbol"></span></span></span>
<info></info>

$('.Price-amount').each(function() {
  if ($(this).text('0.00')) {
    $(this).replaceWith('<div class="info"><img src="/icons8-informaciya-24.png"><div class="info-text">Узнать цену - "какой-то текст"</div></div>');
  }
  });

https://jsfiddle.net/bfza30mL/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pastukhov, 2020-05-07
@Code-NaN

$('.Price-amount').each(function(index, el) {
  if ($(el).text().includes('0.00')) {
    $(el).replaceWith('<div class="info"><img src="/icons8-informaciya-24.png"><div class="info-text">Узнать цену - "какой-то текст"</div></div>');
  }
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question