Jump to content

Adding an "or" to Javascript?


Wardy_7

Recommended Posts

Hi,

I have some code that I want to include an "or" option into the code but not having much luck with it.

 

if(anchorSrc.match("mysite.co.uk")&&anchorVal.match("Great Site"))

 

Basically the above code makes sure that a link to mysite.co.uk is in place and that it uses the link text "Great Site".

What I want to do is add that the "anchorVal.match" can be "Great Site" OR "Super Site" if that makes sense but I'm not having much luck with it.

 

Any help would be appreciated, thanks!

Link to comment
https://forums.phpfreaks.com/topic/274773-adding-an-or-to-javascript/
Share on other sites

|| is the operator to use for a logical-or condition. As in Cond1 || Cond2.

 

So just create a second anchorVal.match test and stick it after the current one and put a || between them.  You also want to surround the whole condition (both anchorVal tests) in parenthesis to make sure everything is evaluated in the proper order.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.