user4037798
user4037798

Reputation: 101

Get meta tag content in jQuery

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?

Upvotes: 9

Views: 23300

Answers (3)

matthias_h
matthias_h

Reputation: 11416

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.

Upvotes: 9

Wayne Porter
Wayne Porter

Reputation: 66

It looks like your quotes are backwards. This little sample sets the variable biz to what you have in content.

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

Upvotes: 1

Cohars
Cohars

Reputation: 4012

Works for me here. Be careful to wait for the DOM to be ready. With jQuery:

$(function() { /* ...code here.... */ });

Or maybe the problem is pageDetails. But we don't have this part of the code. What you could/should do is probably:

var $pageDetails = $('head');

Hope this helped.

NOTE : the $ before pageDetails is just here to know that it's a jQuery object. It's quite a good practice I think.

Upvotes: 0

Related Questions