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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:18:43+00:00 2026-05-31T19:18:43+00:00

HTML: I’ve attached a simplified example of the problem I’m facing: <h2>Product2</h2> <div id=products>

  • 0

HTML:
I’ve attached a simplified example of the problem I’m facing:

<h2>Product2</h2>
<div id="products">

    <a class="my-product1" href="#"><span>my-product1<span></a>
    <a class="my-product2" href="#"><span>my-product2<span></a>
    <a class="my-product3" href="#"><span>my-product3<span></a>
    <a class="my-product4" href="#"><span>my-product4<span></a>
    <a class="my-product5" href="#"><span>my-product5<span></a>

</div>​

Javascript:
I’m already pulling myProduct from the page title and forcing lowercase. Next I’m attempting to remove this product from the group of links based on its class. Its quite possible this is jquery101 however I can’t figure out how to add a class to a link using a variable to determine which class to select. In this example lets assume var myProduct = Product2

function removeProduct(myProduct){
    $("a.myProduct").addClass("display-none");
};

Also, I am still learning so if you have the time a Brief explination of why what i’m doing is wrong would go a long way. Thanks for 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-31T19:18:44+00:00Added an answer on May 31, 2026 at 7:18 pm

    Simply concat the class name to the selector string:

    $("a."+variable)...
    

    Extra info as you requested:

    Don’t use a class “display-none”… change it’s name or use jQuery native code that hides elements(hide(docs))

    function removeProduct(myProduct){
        $("a." + myProduct).hide();
    };
    

    Changing css rules is with the css(docs) function:

    function removeProduct(myProduct){
        $("a." + myProduct).css('display', 'none');
    };
    

    Adding class is with addClass function:

    function removeProduct(myProduct){
        $("a." + myProduct).addClass('someClass');
    };
    

    Change myProduct and removeProduct names to more meaningful variable names:

    function hideAnchorElement(className){
        $("a." + className).hide();        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Html looks like: <div class=ticker> <div class=news-heading>Latest News:</div> <span class=active_ticker><a href=#> 1] Lorem ipsum
HTML code <div class='case'> <a href=http://localhost/DXXX/case/reqirement.doc rel=case> view</a> </div> Jquery code $(.case).live('click', function(){ $.fancybox({
HTML <div class=productDescriptionWrapper> <p>A worm worth getting your hands dirty over. With over six
HTML: <body> <p><a href=# class=link >Apples</a> <a href=# class=link >Berries</a> <a href=# class=link>Carrots</a></p> <select
Html <div class=lang-currency-field> <div class=lang-currency-links>links here</div> </div> jQuery <script> $('.lang-currency-button').click(function() { $('.lang-currency-field').fadeIn(); }); $('.lang-currency-links').click(function()
html structure: <form method=post id=comment-form accept-charset=UTF-8> <div class=form-item form-type-textfield form-item-name> <input type=text id=edit-name name=name
HTML Sorted it for seo <div class=content>Content</div> <div class=nav1> <ul> <li>nav 1</li> <li>nav 2</li>
HTML: <td align=center width=100%> <a class=Forum_ib_moderate href=Default.aspx title=Moderate></a> <a class=Forum_ib_admin href=Default.aspx title=Admin></a> ... CSS:
HTML <div id=header>top of page</div> <div class=message>hello, how are you</div> <div class=message>I am fine</div>
HTML: <div id=div1> <div class=row > <div class=span2 > <input type=button value= name=btn1/> </div>

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.