ether ether - 14 days ago 4x
jQuery Question

Multiple if statements with multiple conditions?

I'm trying to check my page's

tag for certain key words, to show/hide a div. Each state (4 states) have 4 differrent keywords they could have in the title. I'm trying to figure out how I can write my if statement so it says

If title has "word 1" or "word 2" or "word 3" or "word 4" do this function

Currently, I have it written like this:

if ($("title").text() == "Marketing" || "Marketing Product Support" || "Inbound Marketing Best Practices" || "Marketing Certification Help") {

if ($("title").text() == "Sales" || "Sales Product Support" || "Inbound Sales Best Practices" || "Sales Certification Help") {

if ($("title").text() == "COS Design" || "COS Design Support" || "Share Your Work" || "Design Certification Help") {

if ($("title").text() == "community Ideas") {

But this doesn't seem to hide/show the divs I'd like, am I missing something? or is there a better way to do this?

Thanks for the help!


I would probably use a switch statement instead.

    switch ( jQuery('title').text() )
       case "Marketing":
       case "Marketing Product Support":
       case "Inbound Marketing Best Practices": 
       case "Sales":
       case "Sales Product Support":
       case "Inbound Sales Best Practices":