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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:56+00:00 2026-06-13T22:05:56+00:00

*EDIT I have a list in my HTML called #wordlist. In this list I

  • 0

*EDIT

I have a list in my HTML called “#wordlist”. In this list I hold the words in my game, the attached audio and the attached image to each word. This all works fine.

Because there will be different versions of the game, I have been asked to take some of the variables capable of changing the amount of words to complete, size of the grid etc; and place them as data-attributes in the list. (Making all the editing factors available in one place).

The problem is I can’t get my head around how I am going to type a value in for something like “number-input” below and that changing the variable “numberInput” in the script.

Is this possible to do?

Here is the list (data-word, data-audio and data-pic are all OK)

<ul id="wordlist">
        <li data-audio="" data-pic="images/one.png" data-word="one" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/two.png" data-word="two" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/three.png" data-word="three" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/four.png" data-word="four" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/five.png" data-word="five" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/six.png" data-word="six" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/seven.png" data-word="seven" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/eight.png" data-word="eight" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/nine.png" data-word="nine" data-number-input="" data-completion-number"" data-grid=""></li>
        <li data-audio="" data-pic="images/ten.png" data-word="ten" data-number-input="" data-completion-number"" data-grid=""></li>
</ul>

Here are the variable that I need to change through the data-attributes in the HTML

var numberInput = 2;
var completionNumber = 2;
var smallGrid = {
    x: 4,
    y: 4
};
var largeGrid = {
    x: 8,
    y: 6
};

So basically So if "data-number-input="2" this would make the variable "numberInput = 2;" in the script

  • 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-13T22:05:57+00:00Added an answer on June 13, 2026 at 10:05 pm

    First of all, your html wasn’t good at all, you must change it to this:

    (data attributes were corrected…)

    HTML:

    <ul id="wordlist">
            <li data-audio="" data-pic="images/one.png" data-word="one" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/two.png" data-word="two" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/three.png" data-word="three" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/four.png" data-word="four" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/five.png" data-word="five" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/six.png" data-word="six" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/seven.png" data-word="seven" data-number-input="" data-completion-number="" data-grid=""></li>
            <li data-audio="" data-pic="images/eight.png" data-word="eight" data-number-input="" data-completion-number="" data-grid=""></li>
    </ul>​
    

    Then, to assign new values to the data attributes, use the following. In this case I just affected the first li but you can do a loop or .map() in jQuery if you want to change all of them.

    Live DEMO: http://jsfiddle.net/oscarj24/qWyj6/1/

    jQuery code:

    var numberInput = 2;
    var completionNumber = 2;
    var smallGrid = {
        x: 4,
        y: 4
    };
    
    //In this case, this is just affecting the first 'li' inside 'ul' that's why '.eq(0)' is used.
    elem = $('ul#wordlist li').eq(0);
    elem.data('number-input', numberInput.toString());
    elem.data('completion-number', completionNumber.toString());
    elem.data('grid', smallGrid.x + ',' + smallGrid.y);
    
    //Print new 'data' attributes in console to look they've changed.
    console.log(elem.data('number-input'));
    console.log(elem.data('completion-number'));
    console.log(elem.data('grid'));
    

    Changing all li attributes:

    just do this using jQuery, this is like the “equivalent” of a loop:

    Live DEMO: http://jsfiddle.net/oscarj24/qWyj6/2/

    (In live demo check browser’s console to see the output)

    $('ul#wordlist li').map(function(i, v) {
        $(this).data('number-input', numberInput.toString());
        $(this).data('completion-number', completionNumber.toString());
        $(this).data('grid', smallGrid.x + ',' + smallGrid.y);
    });​
    

    If you want to get the data attribute from a li and put in a variable, just do this:

    //Getting 'number-input' attribute from the first 'li':
    var numberInput = $('ul#wordlist li').eq(0).data('number-input');
    

    But, If you want to get all data attributes from all li and put them in variables or javascript object, just do this:

    var data = $('ul#wordlist li').map(function(i, v) {
    
        var numberInput = $(this).data('number-input');
        var completionNumber = $(this).data('completion-number');
        var gridX = $(this).data('grid').split(',')[0];
        var gridY = $(this).data('grid').split(',')[1];
    
        return {
            numberInput: numberInput,
            completionNumber: completionNumber,
            grid: {
                x: gridX,
                y: gridY
            }
        };
    }).get();
    

    Live DEMO: http://jsfiddle.net/oscarj24/qWyj6/3/

    This will be the output:

    enter image description here

    And, to get for example the number-input value from the first li of this object, just do this:

    console.log(data[0].numberInput);
    

    Hope this helps 🙂

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

Sidebar

Related Questions

I have a list of input type radio buttons in formview (edit mode) and
so i have a Parents controller with list and edit view for it (to
EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i
I have a field called links that accepts a list of URLs separated by
I have this page as you can see in image. this page contains three
Here's the situation, I have a list of about 20 properties (called Attributes) that
I have a list of items (which are HTML table rows, extracted with Beautiful
Hello I have an edit item form. From this view, look at item.current_item_status_date .
I have a view called Associations that has a drop down list and a
I have an action called Sessies. In this action i am creating 'Sessies' objects

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.