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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.