Try to search your question here, if you can't find : Ask Any Question Now ?

How to create a dynamic array based on checkbox data-attribute value

HomeCategory: stackoverflowHow to create a dynamic array based on checkbox data-attribute value
Avatarpragati asked 3 weeks ago

if I click on one checkbox, need to create a dynamic array based on its data-attribute value and push all checked checkbox value with same data-attribute value to this array.

Ex: if i click on height,i need to create an array with its data-attribute value and push all checkbox with checked value in this array

<input type="checkbox" name="" class="checkbox" data-parent="1" value="1">brand
<input type="checkbox" name="" class="checkbox" data-parent="2" value="2">style
<input type="checkbox" name="" class="checkbox" data-parent="3" value="3">height
<input type="checkbox" name="" class="checkbox" data-parent="4" value="4">width
<input type="checkbox" name="" class="checkbox" data-parent="2" value="5">style
<input type="checkbox" name="" class="checkbox" data-parent="3" value="6">height
<input type="checkbox" name="" class="checkbox" data-parent="3" value="7">height
    <script >
        $('.checkbox').click(function(){
            var newarray = [];
            var id = $(this).val();
            var pid = $(this).attr('data-parent');
            newarray[pid] = id;
        });

    </script>
1 Answers
Best Answer
AvatarFernando answered 3 weeks ago
Your Answer

20 + 16 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com