36

I want to select in Jquery the main photo in a web page, I just have the url page. so I decided to use the meta written for Facebook sharing.

I want to select the content of : meta property="og:image" content="http://blablabla.jpg"

I wrote this, but it doesn't work: $("meta[property=og:image]").attr("content");

Any ideas ? Thank you

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
Maxxx
  • 1,179
  • 3
  • 16
  • 21

2 Answers2

84

$('meta[property="og:image"]').attr('content')

http://jsfiddle.net/ZxmCw/

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • It's minor but since you can have multiple og:image tags I added in: $('meta[property="og:image"]:eq(0)').attr('content'). jUQery selectors FTW – sidonaldson Jan 10 '14 at 11:14
8

:image is parsed as a pseudo-selector. I think you need quotes around "og:image"

Savageman
  • 9,257
  • 6
  • 40
  • 50