views:

49

answers:

3

I want to get page_tag information from the page and want to make sure that DOM for this page is already ready before getting the page tag information.

I am doing

$(document).ready(
{
   alert("test");
   var page_tag : $("head meta[name='page_tag']").attr('content');
   page_tag : (page_tag) ? page_tag : '';
}

But it gives me errors,

missing : after property id
alert("Check if document is ready");\n

Any suggestions on what could be the possible reasons for it or any other way of checking if the dom is ready or not before getting page_tag information.

+4  A: 

try

$(document).ready(function() {
   var page_tag = $("head meta[name='page_tag']").attr('content');
   alert(page_tag);
});

The ready() function requires you to pass in a function that it will execute when the document is ready.

jessegavin
A: 

I'm pretty sure it should be:

$(document).ready(function() {
   alert("test");
   var page_tag = $("head meta[name='page_tag']").attr('content');
   page_tag = (page_tag) ? page_tag : '';
}

You need to use a = instead of :

webdestroya
+2  A: 

You have a syntax error, you are using : instead of = to make the assignment:

var page_tag = $("head meta[name='page_tag']").attr('content');
page_tag = (page_tag) ? page_tag : '';

Or simply:

var page_tag = $("head meta[name='page_tag']").attr('content') || '';

The above will work, because the attr method returns a String or undefined if the attribute is not present.

CMS