0
<meta itemprop="price" content="175.03">

I want to read the content of the meta tag in this case I want the output 175.03 using javascript I have tried the following jquery code but I want to do it using javascript.

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

any help would be appreciated.

Kumar
  • 13
  • 2

1 Answers1

0

https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute

var value = document.querySelector('meta[itemprop="price"]').getAttribute("content");
console.log(value)
<meta itemprop="price" content="175.03">

Or you can also go directly for the Element's DOM content property

var value = document.querySelector('meta[itemprop="price"]').content;
console.log(value)
<meta itemprop="price" content="175.03">

http://javascript.info/dom-attributes-and-properties

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313