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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:41:16+00:00 2026-06-06T12:41:16+00:00

This is heavily trimmed down source code from a webpage I’m working on right

  • 0

This is heavily trimmed down source code from a webpage I’m working on right now.

<!--// GRID ENTRY //-->
    <li class="entry" id="sjDDulC8wt">
        <div class="entry_actions">
            <ul class="entry_actions">
                <li class='have_it'>
<a href='javascript: haveItem("name", "id", "none")'  target='_self' title='Have It' class='have_it'>%</a></li>
            </ul>
        </div>
    </li>

Inside the haveItem() function I’m trying to change the class of the <a> element from ‘have_it’ to ‘have_it selected’ to change the appearance of the element. The reason for the id is because I have dozens of these elements on the page. The javascript I’m currently using is:

var targetA = document.getElementbyID(sjDDulC8wt).getElementsbyTitle("Have_it"); 
targetA.removeClass("have_it").addClass("have_it selected");

When I click the link, the haveItem() function runs, but it doesn’t change the class. How can I change my script so that clicking the link will change the class?

  • 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-06T12:41:17+00:00Added an answer on June 6, 2026 at 12:41 pm

    I am assuming you are using jQuery since you are using removeClass() and addClass. Otherwise, I would recommend you link to jQuery so that the code below works, or stick with only JavaScript.

    var targetA = $('#sjDDulC8wt .have_it');
    targetA.addClass('selected');
    

    For future reference, here are some things about your code that you can improve:

    1. getElementById() accepts the id of the element you want to retrieve as a string. Basically, you should wrap your ID in ' or "
    2. Be careful where you are putting spaces and underscores. They are not the same thing. Your list item has the title Have It, while your JavaScript has Have_it.
    3. Capitalization matters. Have_It is not the same thing as Have_it. Be careful with this when you try to get elements by ID.
    4. A class with spaces in it is actually multiple classes. have_it selected actually has both the have_it class and the selected class. Therefore it not necessary to remove have_it and then add have_it selected – you can go straight to adding the selected class.
    5. The function getElementbyTitle() does not currently exist in JavaScript. Also, be careful again about capitalization. Typically, the first letter of every word in a function is capitalized. Thus, if it did exist it would be called getElementByTitle() (notice the B instead of b).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been contributing heavily to this open source project that aims to help
Been working on this for a while now and I think I've finally cracked
I have some code like, this code is used very heavily: using (HttpWebResponse r
I'm heavily basing my code off of this excellent tutorial at Ars Technica, so
This is heavily simplified for the sake of the question. Say I have a
I'm sure this depends heavily on a few variables. Here are the ones I
Warning: This question has been heavily edited. I tried my best to guess the
I have this c# web app that relies heavily on two dll files that
this is my code that I write it but I want to use LINQ
I've heavily edited this question because responses indicated I wasn't being clear problem: UI

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.