Replace value after tag, but within div

0

I have the HTML code, and I need to do the decimal substitution at the end of the div, the project is doing a reverse proxy for a site, and I have to put the value of the "changed" tag in the place where the "11.00 " the HTML is this:

<div class="osg-outcome__price" changed="7.14">
    <i class="osg-outcome__trend"></i>
    11.00
</div>

I have tried to do this as follows:

var value = parseFloat($(this).text());
var ht = $(this).html().replace(value,$(this).attr("changed"));
$(this).html(ht);

But the problem is that the div value constantly changes based on a websocket, so when I change the value that way, the websocket stops updating the div for some reason. The maximum I could get was to put the value of interest inside the 'changed' tag, now I need to take that value to div without touching <i class="osg-outcome__trend"> .

Is there a way to do this in CSS? I think I would avoid those problems. Or a more accurate jQuery solution?

    
asked by anonymous 01.03.2018 / 15:37

1 answer

1

Adds .toFixed(2) to value in this line of replace :

var ht = $(this).html().replace(value.toFixed(2),$(this).attr("changed"));

parseFloat dispenses zeros from decimals:

11.00 --> 11
11.10 --> 11.1

So replace will not work because it will not find the value correctly. The toFixed(2) will keep the zeros too:

11.00 --> 11.00
11.10 --> 11.10
    
01.03.2018 / 16:16