Search code examples
htmlstore

Is storing a string within the id of a div advisable?


Alright, so I'm quite new to css/html/javascript, and I was thinking of storing a value temporarily within the ID of a div. I won't use the ID to select or css, just to store the value. Is this recommended?


Solution

  • I would recommend that you consider looking at data-xx attributes instead, e.g.:

    <div id="1" data-info="Your string goes here"></div>
    

    As that is what these are designed for.

    https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes