show div only if meta tag exists Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of show div only if meta tag exists without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have an include file that is used in different applications and different platforms.

I want to show a div below

    <div id="my-menu" class="dropdown"></div>

only if there is a meta tag – its hidden via display:none by default in the css

the meta tag would be something like this

    <meta name="login-menu" content="show"/>

if they add the above meta on their applications i want show #my-menu div.

what is the best way to do this via jquery?, here is a start

   if ($('meta[name="login-menu"]').attr('content')) {
       $( "#my-menu" ).show();
     }

Answer

You should check the length to see if it exists:

if ($('meta[name="login-menu"]').length) {
    $( "#my-menu" ).show();
}
We are here to answer your question about show div only if meta tag exists - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji