Hi,
I'm trying to pass JSON array values into my javascript file and use the values as selectors to call methods on corresponding html divs.
for example:
function clickEvents(items) {
for (var r = 0; r < items.length; r++) {
var omega = items[r].id +;
$(omega).click(function() {
alert('Thanks for adding item number #' + omega ' to your cart!');
});
}
where my JSON looks like this:
{
"Items" : [{
"header: "apple",
"id": 5000
}, {
"header": "banana",
"id":5001
}, {
"header": "pear",
"id": 5002
}]
}
unfortunately, its not working properly. I can't seem to get the selectors to match up. Does anyone know the proper syntax for this type of approach or have ideas for other approaches?
when i do this, it works:
function clickEvents(items) {
$('#5001').click(function() {
alert('hi');
});
}