当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Jquery: If page has meta content- have css

问题描述:

Trying to set up a div, visible only from pages with certain meta content

Here is the code. Picked up the first line somewhere. I'm a JQ noob, so pretty sure there is a mistake. But, for some reason, not much info on reading meta with jquery out there.

var m = $("meta[content=submenu]");

$(".extramenulevel").css('display','block');

网友答案:

Just use something like:

var author = $('meta[name=author]').attr("content");

(source: Is it possible to use jQuery to read meta tags)

so you could do in your case something like:

if($('meta[content=submenu]').length>0)
    $(".extramenulevel").css('display','block');
网友答案:

With little information to go on, and on the assumption that the meta content/element is not necessarily a child element of the element you're trying to style:

$(".extramenulevel").css('display', $('meta[content="submenu"]').length ? 'block' : 'none');
网友答案:

try this

var m = $("meta[content=submenu]");    
if($("ELEMENT").contains("$m")) {
  $(".extramenulevel").css('display','block'); // do stuff 
}

you just have to change ELEMENT with the html address of the object that if contains the variable m will attribute to .extramenulevel the css display: block

分享给朋友:
您可能感兴趣的文章:
随机阅读: