Get meta tag content in jQuery

user4037798 picture user4037798 · Sep 16, 2014 · Viewed 15.1k times · Source

I would like to get the meta content where pageDetails is my HTML page.

$(pageDetails).find('meta[name="biz-id"]').attr("content")

My HTML code is:

<meta name="biz-id" content="q6aDxTSK7njG7qWB1tSV5g">

Why my returned value is always empty?

Answer

matthias_h picture matthias_h · Sep 16, 2014

Have you already tried

var bizId = $("meta[name='biz-id']").attr("content");  

In addition, in your query $(pageDetails).find('meta[name="biz-id"]').attr("content") it's not clear if you have pageDetails defined previously. Though this has already been noticed in another answer and the question seems to be resolved, just mentioning it here because of being informed that I shouln't have given this info in the comments below this answer but as comment below the OP.