Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:06:01+00:00 2026-06-16T02:06:01+00:00

Possible Duplicate: Check variable equality against a list of values Javascript if statement with

  • 0

Possible Duplicate:
Check variable equality against a list of values
Javascript if statement with multiple permissible conditions

I must click the same 21 of 253 items (li) in a dropdown list (ul).

Scrolling I’ll have to do this for the same list on 500+ pages, I figured I could Javascript inject each ul, loop through and click each li which happens to be one of the 21.
It seems I cannot do something like

 if(item[i] === ('aasdf'|'basdf'|'cwefw'|'asdfd'|'trehe'|'ferth'|'erthg'|'erthh'|'ierth'|'jeth'|'kerth'|'lerth'|'merth'|'psdfg'|'gregq'|'rsrgs'|'sress'|'srget'|'sergu'|'sdfgsv'))

Is there a syntactically cleaner way of writing this ugly if statement below?

var item = document.getElementById('myDropdownList').getElementsByTagName('li');

for (i=0;i<item.length;i++){

    if(item[i].innerText === 'Argentina' | item[i].innerText === 'Australia' | item[i].innerText === 'Brazil' | item[i].innerText === 'Canada' | item[i].innerText === 'China' | item[i].innerText === 'Colombia' | item[i].innerText === 'France' | item[i].innerText === 'Germany' | item[i].innerText === 'Indonesia' | item[i].innerText === 'India' | item[i].innerText === 'Italy' | item[i].innerText === 'Japan' | item[i].innerText === 'Malaysia' | item[i].innerText === 'Mexico' | item[i].innerText === 'Philippines' | item[i].innerText === 'Russia' | item[i].innerText === 'South Africa' | item[i].innerText === 'Sweden' | item[i].innerText === 'Switzerland' | item[i].innerText === 'United Kingdom' | item[i].innerText === 'USA'){

    item[i].click();

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:06:01+00:00Added an answer on June 16, 2026 at 2:06 am

    You could use a variable and multiple comparison, but that’s still lengthy:

    var text = item[i].innerText;
    if (text === 'Argentina' || text === 'Australia' || text === 'Brazil' || text === 'Canada' || text === 'China' || text === 'Colombia' || text === 'France' || text === 'Germany' || text === 'Indonesia' || text === 'India' || text === 'Italy' || text === 'Japan' || text === 'Malaysia' || text === 'Mexico' || text === 'Philippines' || text === 'Russia' || text === 'South Africa' || text === 'Sweden' || text === 'Switzerland' || text === 'United Kingdom' || text === 'USA')
    

    Or you could just use an array and check if the string is contained in it.

    var matches = ['Argentina','Australia','Brazil','Canada','China','Colombia','France','Germany','Indonesia','India','Italy','Japan','Malaysia','Mexico','Philippines','Russia','South Africa','Sweden','Switzerland','United Kingdom','USA'];
    if (~ matches.indexOf(item[i].innerText) …
    

    Yet, for the complicated != -1 comparison and the lack of native indexOf in older IEs, people tend to use regexes:

    var regex = /Argentina|Australia|Brazil|Canada|China|Colombia|France|Germany|Indonesia|India|Italy|Japan|Malaysia|Mexico|Philippines|Russia|South Africa|Sweden|Switzerland|United Kingdom|USA/
    if (regex.test(item[i].innerText)) …
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to check a not defined variable in javascript Determining if a
Possible Duplicate: How can I check if a javascript variable is function type? How
Possible Duplicate: How can I check whether a variable is defined in JavaScript? Is
Possible Duplicate: How to check for undefined or null variable in javascript I want
Possible Duplicate: How do you check if a variable is an array in JavaScript?
Possible Duplicate: Check if a variable contains a numerical value in Javascript? How do
Possible Duplicate: Check if a variable is empty Simple PHP question: I have this
Possible Duplicate: How do you check if list is blank? def CleanWhiteSpace(theDict) : stuff=[]
Possible Duplicate: How can you check for a #hash in a URL using JavaScript?
Possible Duplicate: How can you check for a #hash in a URL using JavaScript?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.