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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:11:12+00:00 2026-06-10T21:11:12+00:00

I want to do somethings in jQuery to all the elements which match on

  • 0

I want to do somethings in jQuery to all the elements which match on a certain class name. The class name comes from a variable. How do I do the select using by class using my variable?

var x = $(this).attr('href').slice(1);

this will set x equal to the name of the class I want.

now I want to select all the elements with that class name

I try stuff like this but it doesn’t work

$(.x.show().addClass('active').siblings().hide().removeClass('active');

basic basically I want affect all the elements with where class = x

Finally, instead of setting x to the class name, can I just get my array of classes in the first variable assignment?

i.e. instead of

var x = $(this).attr('href').slice(1);

can I do this [pseudo code]:

var x = classname is $(this).attr('href').slice(1);
  • 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-10T21:11:13+00:00Added an answer on June 10, 2026 at 9:11 pm

    Selector is nothing more than just a string. So you could use

    $('.' + classname)
    

    where classname is a variable that holds particular class name

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

Sidebar

Related Questions

I want to call a event everytime elements are added. Im using JQuery, which
I want to select all the select elements that have a value of -1
I would like to select with jQuery all td elements of a table given
I want to execute some function on all class elements. How can i do
I have a HTML Table which in which i want to manipulate using JQuery
I would like to select all jquery UI button that live inside all <div>
I'm creating div elements (for entering notes) on the fly using jtemplates which looks
I have elements like user[0][foo], user[0][bar], user[1][foo], user[2][bar] which are names of select tags.
I want to implement something with jquery, simple javascript and java but I don't
I want to contain jQuery and was hoping I could do something like the

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.