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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:30:09+00:00 2026-06-03T18:30:09+00:00

Ok. First let me say that I just started learning jQuery and I’ve taken

  • 0

Ok. First let me say that I just started learning jQuery and I’ve taken various challenges upon myself so I can learn faster. Today, I have a very novice question, so apologies if the answer to this is obvious.
I am using JQuery to display a particular value when it’s corresponding list is clicked.

I don’t know what I’m doing wrong. Basically, I’ve created an unorded list and what I want to achieve is, if each link is clicked, change the value of the span which should be specific for each list item (so each list item will have different span value). But the script below is not working. Any idea on what I’m doing wrong or what I should do?:-

<ul class="stag">
    <li><a class="$200" href="#d1">Display</a></li>
    <li><a class="$300" href="#d2">Shirt</a></li>
    <li><a class="$400" href="#d3">Dress</a></li>
    <li class="amount"></li>
    **<span>$200</span>**
</ul>

this is the jQuery code:-

 $(document).ready(function() {
      ("ul.stag li").click(function(){
        var activePd = $(this).find("a").attr("class");    //the clicked list
        $(".stag span").html(activePd.html());
            return false; 

       });
    });

Can anyone help?. Thanks guys 🙂

  • 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-03T18:30:10+00:00Added an answer on June 3, 2026 at 6:30 pm

    A class name must begin with a character from a to Z. You’re starting with a dollar sign, so your class name is invalid. You’ll have to find some other way of storing the value of the <a> element. Here’s a better version of your script where I use the data attribute instead of the class to store your value:

    HTML:

    <ul class="stag">
        <li><a data-cost= "$200" href="#d1">Display</a></li>
        <li><a data-cost ="$300" href="#d2">Shirt</a></li>
        <li><a data-cost ="$400" href="#d3">Dress</a></li>
        <li class="amount"></li>
        <li><span>$200</span></li>
    </ul>​
    

    Javascript:

    $(document).ready(function() {
        $("ul.stag li").click(function() {
            var activePd = $(this).find("a").data("cost"); //the clicked list
            $(".stag li span").html(activePd);
            return false;
        });
    });​
    

    Also important is that you can’t call .html() on a string (which is what activePd is), and you don’t even need to because it’s already the value you want.

    Also, like Rocket pointed out in the comments below, you can’t have a <span> in a <ul>. I put it in an <li> for now and changed the jQuery selector accordingly.

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

Sidebar

Related Questions

Hi there First of all just let me say that I'm new in Python
First let me say that I can remote debug a release build on the
First let me say that I learned scripting by myself so my approaches may
First of all let me just say that I am new to nHibernate so
First of all, let me just say that I'm using the PHP framework Yii,
First let me say that I really feel directionless on this question. I am
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
First, let me say that I'm a complete beginner at Python. I've never learned
Let's say I have a form that collects a first name and a last
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},

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.