0

Any idea can I use .data attribute in HTML select box?I red HTML5 documents but I didn't find any information that could help me.

Is it legal:

<span>Select depatament</span>
<span>
    <select id="department" onchange="EnableSelectBox(this)" data-spacing="10cm">
        <option selected disabled>-Select-</option>
    </select>
</span>
3

3 Answers 3

1

Yes it fine to use data in Html5 tag. I don't know why you want to use in such a way, but you can use it.

for example like this

$(document).ready(function() { alert($('#department').data('spacing')); });

jsfiddle link

Sign up to request clarification or add additional context in comments.

Comments

1

Using data attributes

Any attribute on any element whose attribute name starts with data- is a data attribute.

To answer the question: Yes. You can use data attributes on any element.

Comments

1

It works fine. Test in JS using:

alert(document.getElementById("department").getAttribute("data-spacing"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.