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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:07:00+00:00 2026-06-13T00:07:00+00:00

I have a list in HTML that holds the attributes data-answer and data-sum. The

  • 0

I have a list in HTML that holds the attributes data-answer and data-sum. The grid is populated with hidden answers. When a hidden answer is highlighted the user uses the sum to work out what the answer is. At the moment when an answer is highlighted the sum is not the correct one linked in the HTML, so the user cannot work it out.

What is wrong with my code, why won’t it pair these two attributes up. Is it because I haven’t set a variable for answers?

I have this list…

<ul style="display:none;" id="answerlist">

    <li data-answer="1" data-sum="4 - 3 ="></li>

    <li data-answer="2" data-sum="7 - 5 ="></li>

    <li data-answer="3" data-sum="1 + 2 ="></li>

    <li data-answer="4" data-sum="1 + 3 ="></li>

    <li data-answer="5" data-sum="4 - 3 ="></li>

    <li data-answer="6" data-sum="10 - 4 ="></li>

    <li data-answer="7" data-sum="4 + 3 ="></li>

    <li data-answer="8" data-sum="2 x 4 ="></li>

    <li data-answer="9" data-sum="4 + 5 ="></li>

    <li data-answer="10" data-sum="1 x 10 ="></li>

    <li data-answer="11" data-sum="10 + 1 ="></li>

    <li data-answer="12" data-sum="2 x 6 ="></li>

    <li data-answer="13" data-sum="9 + 4 ="></li>

    <li data-answer="14" data-sum="2 x 7 ="></li>

    <li data-answer="15" data-sum="11 + 4 ="></li>

  </ul>

The answer works fine, but when I go to pull the question into the div – “.sumstyle” it is always the wrong one to the question.

var sum = $('#answerlist li[data-answer=' + answer + ']').data('sum');
$('.sumstyle').text(sum);

Is there something wrong with the way I am setting the variable for sum?

Here’s a fiddle http://jsfiddle.net/ZAfVZ/21/

  • 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-13T00:07:00+00:00Added an answer on June 13, 2026 at 12:07 am

    Ok, I’ve had a look at the Fiddle, and the reason this:

    var sum= $('#answerlist li[data-answer="'+answer+'"]').data('sum');
    

    …on line 120 isn’t finding the li element you want is that the answer variable being written into the JQuery selector has no value. This means you’re really doing this:

    var sum= $('#answerlist li[data-answer=""]').data('sum');
    

    …which is looking for the li element where the data-answer attribute has no value, which does not exist.

    Where is the value of answer on that line supposed to come from? There’s a local answer variable used in the earlier for / while loop around line 100 – is that it?

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

Sidebar

Related Questions

I have a HTML form that accepts a comma separated list of tags, which
I have a base.html template that contains a list of links. Example: <div id=sidebar1>
I have an asp.net UserControl that writes HTML content from a SharePoint list to
I have a webpage written in HTML. I have a dropdown list that is
I have created a populated dropdown list in HTML. When the two dropdowns have
I have a html list that looks like this: animals (45) houses (36) computers
I have a UL html list that looks like this: <div id=scroller> <ul> <li>item
Consider we have a multi-level html list that looks like this: <ul class=catalog> <li>
So I currently have a registration.html page that holds two dates in a drop
I have a table, sessionBasket, that holds a list of the items in 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.