2

Let's say I have this:

<meta prop="foo" name="randomname1">
<meta prop="bar" name="randomname2">
<meta prop="foobar" name="randomname3">

And I want to get the value of name property but only for prop="bar". Order of the tags might not be always the same, so indexes are not a solution.

  • 3
    Possible duplicate of [Is it possible to use jQuery to read meta tags](http://stackoverflow.com/questions/1036351/is-it-possible-to-use-jquery-to-read-meta-tags) – Rajesh Sep 21 '16 at 08:03

2 Answers2

2

alert($('[prop=bar]').attr('name'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta prop="foo" name="randomname1">
<meta prop="bar" name="randomname2">
<meta prop="foobar" name="randomname3">

Use attr selector

Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.

guradio
  • 15,122
  • 3
  • 30
  • 47
1

You can use attr() to get something attribute from your html element

try this:

var a = $('meta[prop="bar"]').attr('name');
console.log(a);
// 'randomname2'
Bartłomiej Gładys
  • 4,295
  • 1
  • 9
  • 19