Set content value of itemprop using jQuery
Html:
<meta itemprop="price" content="34,95 € " />
I need to dynamically update the price. For this I use:
$('meta[itemprop="price"]').attr('content');
What method can be used to replace the price?
+3
alex
source
to share
4 answers
You can simply give the function a attr
second argument, which is the value.
$('meta[itemprop="price"]').attr('content', 'newContent');
//newContent doesn't have to be in quotes, it can be a variable too
Read more about attr
here .
+3
Drown
source
to share
To replace the value of an attribute, give two arguments .attr()
:
$('meta[itemprop="price"]').attr('content', newPrice);
+2
Barmar
source
to share
$('meta[itemprop="price"]').attr('content', newValue);
.attr( attributeName )
is a getter
.attr( attributeName, value )
is a setter
You can read more here: http://api.jquery.com/attr/
+2
Jack zelig
source
to share
Try the following:
$('meta[itemprop="price"]').attr('content',"<<new price>>");
Let me know if this works.
+1
ArinCool
source
to share