I need to dynamically update the ...">

Set content value of itemprop using jQuery

Html:

<meta itemprop="price" content="34,95&nbsp;€ " />

      

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


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


source


To replace the value of an attribute, give two arguments .attr()

:



$('meta[itemprop="price"]').attr('content', newPrice);

      

+2


source


$('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


source


Try the following:

$('meta[itemprop="price"]').attr('content',"<<new price>>");

      

Let me know if this works.

+1


source







All Articles