-1

When price (value) in div .highlight dd is greater than 750, insert element from var somewhere

var CustomOrderText = "<div class='CustomOrderText'>XY</div>";

if there are additional questions, I will be happy to specify. Please do not delete this post (as before). This is a very important question for me.

Edit: *I can´t remove "HTML entity" for space from the price, because I can't interfere in the generation process of the application that makes up HTML

var CustomOrderText = "<div class='CustomOrderText'>XY</div>";
$(CustomOrderText).insertBefore("div.target");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<dl class="sumPrice withVat highlight ">
  <dd>779,70&nbsp;Kč</dd>
</dl>
adiga
  • 34,372
  • 9
  • 61
  • 83

1 Answers1

0

The first problem of your issue - this is a string 779,70 Kč (Not number). No way to find numbers that is greater than "hello" for example - one way is to use regex (Very modular). Related Q: How to find a number in a string using JavaScript?.

Less modular idea is to use replace().

commas to your thousands (the string manipulation should be different): How can I parse a string with a comma thousand separator to a number?

var number_with_commas = '1,125';
number_without_commas = number_with_commas.replace(/,/g, '');
console.log(number_without_commas);

/* jquery example */
var price = $(".price").text().replace(/,/g, '.').replace(/Kč/g, '');
console.log(price);

if(price > 750){
  console.log("price is higher than 750 - do something");
}
<p><span class="price">779,70&nbsp;Kč</span></p>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Ezra Siton
  • 6,887
  • 2
  • 25
  • 37