-3

Is it possible to pass parameters through the load function when using it for multiple images?

var images = {0 : {target_ : 'url', foo : 'foo', bar : 'bar'}, 1 : {target_ : 'url',foo : 'baz', bar : 'qux'}};

for(var image in images){
   var x_ = image.foo;
   var y_ = image.bar;
   $(image.target_).load(function(){
    console.log(x_ + y_);
   });
}
Philip
  • 6,827
  • 13
  • 75
  • 104

1 Answers1

2

Or you can use the data attribute to store additional information's on image's.

And than you can do something like

$(image).load(function(){
    var x__ = $(this).data("x");
    var y__ = $(this).data("y");
});

While the img tag could be something like

<img src="#" data-x="someValx" data-y="someValy"> 
Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89