I have the following line of code:
tpj("#totalcostinclship").empty().append( "<span data-src='"+pricefinal+"' id='totalcostinclship'></span>" ).text(pricefinal);
It first empties the existing element and then appends the new element. pricefinal in this case contains 245 but when I inspect my HTML, this is what I see:
<span data-src="220" id="totalcostinclship">245</span>
The .text is applied but the data-src not at all. Why could that be? 220 is the value of the data-src on page load, so before any jQuery event is started.
tpjis a reference to jQuery, then I am unable to replicate your problem. The given code works absolutely fine: jsfiddle.net/q29Lgwu5. I can only assume you have some other logic which affects the data attribute after you append the new element