Skip to content

Issue - Q. How to use data- attribute in html5? #1

@RockL30

Description

@RockL30

Fixed code since getElementById is not working

According to mdn we can use querySelector -
-> https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

const article = document.querySelector("#electric-cars");

article.dataset.columns; // "10"
article.dataset.indexNumber; // "100"
article.dataset.parent; // "cars"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions