Reputation: 99
How do i get the data object from a html Object that has more than one like element in an array.
<div id='show_box'>
<h6 id="#0" data-choosed="1000">1000</h6>
<h6 id="#1" data-choosed="1000">2000</h6>
<h6 id="#2" data-choosed="1000">3000</h6>
</div>
In the javascript var h6_len=$("#show_box > h6").length;
switch (h6_len) {
case 0:
choosed=$('#show_box > #' + h6_len).data('choosed');
$('#total_box').text(choosed);// this return the drop-down clicked
//this part of the code is working fine.. when the case == 0
break;
case 1:
var h6_1=$('#show_box > h6')[0];
var h6_2=$('#show_box > h6')[1];
/* this is where i am having issues... getting the data value from one of the array the H6 element...
console.log( typeof h6_1);
break;
case 2:
console.log(h6_len);
break;
default:
$('#total_box').empty();
}
Upvotes: 1
Views: 171
Reputation: 4904
HTML
<div id='show_box'>
<h6 id="#0" data-choosed="1000">1000</h6>
<h6 id="#1" data-choosed="2000">2000</h6>
<h6 id="#2" data-choosed="3000">3000</h6>
</div>
jQuery
$('h6').each(function () {
console.log($(this).data('choosed'));
});
Working fiddle. Hopefully this helps.
Upvotes: 1