1

I have a select with several data attributes...

<option data-content="news" data-type="list">News List</option>

Is there a way to get all the data-attributes in a variable?

1 Answer 1

3

Call data with no parameters

var dataObject = $('option').data();
console.log(dataObject);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<option data-content="news" data-type="list">News List</option>

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

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.