Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get meta tag content in jQuery

Tags:

jquery

meta

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?

like image 646
user4037798 Avatar asked Sep 16 '14 20:09

user4037798


People also ask

How do you use meta in HTML?

<meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings. Metadata will not be displayed on the page, but is machine parsable.


1 Answers

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.

like image 72
matthias_h Avatar answered Oct 11 '22 09:10

matthias_h