How to verify that this event will happen after the DOM is ready in jquery?

I want to get page_tag information from a page and I want the DOM for this page to be ready before I get the page tag information.

I do

$(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 this, or any other way of checking whether dom is ready or not, before getting information on tag_page.

+3
source share
3 answers

try

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

The ready () function requires that you pass in a function that will be executed when the document is ready.

+4
source

, : = :

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

:

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

, attr String undefined, .

+2

I am sure this 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 = instead of :

0
source

Source: https://habr.com/ru/post/1743411/


All Articles