I'm not that experienced yet with JavaScript, so I’m probably overlooking something here:
var products = document.getElementsByClassName('product');
var productsLength = products.length;
for(var i = 0; i < productsLength; i++){
var productGender = products[i].attr('data-gender');
if(productGender === triggerVal){
console.log('yes');
} else {
console.log('no');
}
};
It says: products[i].attr
is not a function
I should be able to access it right? The product is just a list item.
Thanks!
attr
is a jQuery method, use getAttribute
http://www.w3schools.com/jsref/met_element_getattribute.asp
var productGender = products[i].getAttribute('data-gender');
Is what you need, you have used jquerys .attr()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With