Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set content value of itemprop with jQuery

Tags:

jquery

Html:

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

I need to update price dynamically. To get it I use:

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

Which method can be used to replace price?

like image 364
alex Avatar asked Jan 10 '23 08:01

alex


2 Answers

You can simply give the attr function a 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.

like image 182
Drown Avatar answered Jan 19 '23 11:01

Drown


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

like image 33
James Hibbard Avatar answered Jan 19 '23 12:01

James Hibbard