0

How I can get multiple checkbox data-attribute (only checked)?

I can get checkbox values, but not data attribute:

<script type="text/javascript">
//export upc
  $('#export_upc').click(function(){
    var arr = $('.checkboxes:checked').map(function(){
        return this.value;
    }).get();
    console.log(arr);
}); 
</script>

I tried return this.data("upc"), but this is not working.

2
  • some markup would be helpful Commented Jan 18, 2016 at 18:26
  • $(this).data('upc') or this.dataset.upc Commented Jan 18, 2016 at 18:26

2 Answers 2

1

this represents DOM element. You should use jquery object $(this) instead.

$(this).data("upc")
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried $(this).attr('upc')

1 Comment

$(this).data('upc') or this.dataset.upc

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.