-2

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');
user3353748
  • 317
  • 1
  • 2
  • 11
  • Have you tried: `if(m.length > 0){ $(".extramenulevel").css('display','block'); }`? – Joe Apr 29 '14 at 19:16
  • it's gonna work on all meta. i need only certain words – user3353748 Apr 29 '14 at 19:19
  • Ok, could you please add more information to the question about what meta content value you want to check for? – Joe Apr 29 '14 at 19:20
  • Also, HTML to give some idea of the structure we're working with. And: "*it's gonna work on all meta. [I] need only certain words*" - what does that even mean? Which words? Where are they? In an attribute, an attribute themself? – David says reinstate Monica Apr 29 '14 at 19:20

3 Answers3

2

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');
David says reinstate Monica
  • 230,743
  • 47
  • 350
  • 385
0

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

Nic
  • 79
  • 10
-1

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');
Community
  • 1
  • 1