Im trying to grab my divs with the class tooltip.
And then do something like this:
var schemes = $(\".tooltip\");
for (var i in schemes) {
var s
var schemes = $(".tooltip");
schemes.each(function(index, elem) {
console.log($(elem).attr('cost'));
});
As a sidenote "cost" is not a valid attribute for any element as far as I know, and you should probably be using data attributes.
If you use for-loop
to iterate jQuery set, you should get the elements with eq()
method, but not using square bracket notation (i.e. []
). The code like $(".tooltip")[i]
will pick up DOM elements, but not jQuery objects.
var schemes = $(".tooltip");
for (var i = 0; i < schemes.length; i++) {
var scheme = schemes.eq(i);
console.log(scheme.attr("cost"));
}
However, you may always use each()
to iterate jQuery set:
$(".tooltip").each(function() {
var scheme = $(this);
console.log(scheme.attr("cost"));
});