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 5954669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:00:13+00:00 2026-05-22T18:00:13+00:00

I am having trouble using variables in jQuery class selectors. The following works: $(‘.contactcapturepage

  • 0

I am having trouble using variables in jQuery class selectors.
The following works:

$('.contactcapturepage > .question-container > .select-container > select').each(function () {...

But the following doesn’t work

var pageType='.contactcapturepage';
$(pageType+' > .question-container > .select-container > select').each(function () {...

How can I use variables within my class selector hierarchy?

Thanks.

EDIT: In response to request for more code:
I’m calling a helper function as follows:

helper_FormMapper(existing.contact, 'objectToForm','.contactcapturepage');

The helper signature:

function helper_FormMapper(object,direction,pageType) {

And then later in the same function:

//$('.contactcapturepage > .question-container > .select-container > select').each(function () {
        $(pageType+' > .question-container > .select-container > select').each(function () {
            var propertyname = $(this).attr('name');
            $.log('processing select:'+propertyname);
            if (propertyname != 'country'
                && propertyname != 'state') {

                if (direction == 'objectToForm') {
                    $("select#" + propertyname + " option").each(function () { this.selected = (this.text == object[propertyname]); });
                }
                else {
                    object[propertyname] = $('#' + propertyname + ' :selected').text();
                }
            }
        });

Note that the commented-out line works, whilst the uncommented version does not work.

EDIT – After further testing the following also does not work:

var path = pageType + ' > .question-container > .text-container > input';
        $(path).each(function () {...

EDIT – But the following DOES work:

var path = '.contactcapturepage > .question-container > .text-container > input';
        $(path).each(function () {...

What’s going on here!

EDIT:
The following also works

pageType = '.contactcapturepage';
    $(pageType + ' > .question-container > .text-container > input').each(function () {

, so it looks like it’s nothing to do with jQuery, but something to do with the function parameter getting corrupted somewhere. Outputting pageType to the console shows it as undefined.

EDIT – Ok – lots of egg on face – bug in my code… Very sorry to have wasted your time

  • 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-22T18:00:14+00:00Added an answer on May 22, 2026 at 6:00 pm

    I can’t commento so I’ll have to write it as an answer.
    Are you sure that the function inside each() is not being invoked, perhaps it is but you are getting some exception inside it.

    if you are using chrome, then I’d set a breakpoint in this line

    $(pageType+' > .question-container > .select-container > select')
    

    then I’d run this in the console

    $(pageType+' > .question-container > .select-container > select').length
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble using a container with my custom class. Every time I
I'm having trouble using variables in my SQL WHERE clause. I'm getting this error:
I am having trouble appending multiple variables to the end of a url using
I'm having trouble using std::auto_ptr . I try to compile the following on Ubuntu
I am new to jQuery and I am having trouble with the syntax, selectors
I am new to jQuery and am having trouble following the documentation. I have
Am having some trouble hooking up instance variables in the visual object editor using
I'm using JQuery to parse some xml and having trouble with the line below:
I'm having some trouble writing a query using variables. Here's my code Dim bondnumber
I'm having trouble getting this <div> to automatically update using jQuery. It's essentially a

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.