We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Data attribute HTML element

Home Forums Puzzles Data attribute HTML element

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40988
    viham1
    Participant

    Hello,

    I am new to verge3d and I am trying to find the most efficient way to pass data from my HTML upon selection of the user in the interface to the puzzles.

    Is there any way to get a custom data-* attribute of an element ? I can’t find any puzzle to do that… Ideally I would like the buttons to contain several data pieces such as :
    data-row : xxx
    data-name : xxx
    and then retrieve them to dynamically select the right object or group in my puzzle.

    Thanks a lot
    Victor

    #40996

    Hi,

    There’s no specific puzzle for that but you can use exec_script with the code retreiving data attributes:
    data_attributes.png

    
    let elem = document.getElementById(VARS['elemId']);
    if (elem !== null) {
        VARS['result'] = elem.dataset[VARS['dataAttrName']];   
    }
    

    You can also wrap it in a function for easier use.

    Attachments:
    You must be logged in to view attached files.

    Co-founder and lead developer at Soft8Soft.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.