Reputation: 399
I have the following html code:
<font class="pricecolor colors_productprice">
<span class="PageText_L483n">
<font class="text colors_text">
<b><span class="PageText_L335n">Our Price</span>: </b>
</font>$101.82Amber
</span>
</font>
i want to change 101.82 in the above html code to the value from the following span tag.
<span class="csqft_price">96.96</span>
That is 101.82 should be replaced by 96.96 dynamically using jquery.That is any value in span tag having class="csqft_price"
sholud be replaced in the above font tag where the value is 101.82
Please advise.
Upvotes: 0
Views: 161
Reputation: 3911
You can do this very simply: you should move this 101.82 in a span tag
and use this below script
$(document).ready(function(){
var text = $('.PageText_L483n').html();
$('.PageText_L483n').children().remove();
var text2=text.replace($('.PageText_L483n').text().trim(),$('.csqft_price').text());
$('.PageText_L483n').html(text2);
});
EDITED
Upvotes: 3
Reputation: 2579
Your question wasn't very clear so I hope this is what you're looking for:
$(document).ready(function(){
var span = $('.pricecolor span');// this includes another font and span tag..
var oldSpan = span.find('font'); //so we can add the Our Price again...
span.find('font').remove(); //remove the font part so we can replace the number
span.html(oldSpan.html() + span.html().replace(/\d+.?\d+/, '<span class="csqft_price">96.96</span>'));
});
Here is an example:
The code isn't very pretty but it might lead you in the right direction...
Upvotes: 0
Reputation: 1525
To add a element using jQuery you can use append. See this link Append
Upvotes: 0