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

  • SEARCH
  • Home
  • 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 6538675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:45:49+00:00 2026-05-25T10:45:49+00:00

I’m trying to concatenate a class selector using multiple variables that come from user

  • 0

I’m trying to concatenate a class selector using multiple variables that come from user input. I’m getting an empty array as an answer.

The user input is captured from dropdown menus and saved as variables:

var changed1 = $("#dropdown1-ddl option:selected").text();
var changed2 = $("#dropdown2-ddl option:selected").text();

There is a list of results that are shown based on whether the list item has that particular class.

$("ul li").hide();    
$("ul li ."+changed1+"."+changed2).parent().show();

The list is setup so that it pulls all the information off of a database and stores the search terms in classes in div tags below each li tag. Hence the showing of the parent.

<ul>
<li>
    <div class="value1"></div>
    <div class="value2"></div>
</li>
<li>
    <div class="value1"></div>
    <div class="value2"></div>
</li> 
</ul>

The JQuery should search across the div’s for all of the div’s that match the search terms and show them.

Currently I can pull the user input and save it as variables. I can search on one variable just fine but adding the second keeps giving an empty array (at least that is the result if I just a console.log to output the result of the concatenation.

  • 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-05-25T10:45:50+00:00Added an answer on May 25, 2026 at 10:45 am

    Your selector currently says that some child element of an li in a ul must have both classes of whatever changed1 and changed2 are equal to.

    But since each div only has one class, you can try the following approach:

    $("ul li").has('.' + changed1).filter(':has(.' + changed2 +')').show();
    

    This filters out first li’s that have a div inside them with class of the value of changed1, and filters that list (of li’s) further for ones that also have a div with a class of the value of changed2, then shows those li’s that match both.

    I’m not sure it’s the most efficient way, but it does work.

    Simple jsFiddle I used to test: http://jsfiddle.net/DCqwH/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.