Having trouble using the $(this)
object inside an .each()
..
Not sure what I'm doing wrong. This works, so its not critical, but I would like to know why it doesn't work with $(this).on("click
instead of $("#b_" + thumb_id).on("click"
//Create a flip button for each attached image.
$(".attached_preview").each(function(){
var att_name = $(this).attr("data-name"), thumb_id = $(this).attr("data-thumb");
//Create the button
var element = document.createElement("input");
element.id = "b_" + thumb_id;
element.type = "button";
element.value = "Flip " + att_name;
//Add button to page
this.parentNode.appendChild(element);
// create function for button.
$("#b_" + thumb_id).on("click",function(e){ //need jQuery object, yet can't use $(this) for some reason. :-(
e.preventDefault(); e.stopImmediatePropagation(); //needed to stop form submission.
//reset the <img> src attribute from the saved copy.
var image = $("#invert"+thumb_id);
image.attr("src",image.attr("data-url"));
image.toggleClass("rotated"); //the bit that actually flips.. used to be so simple!
image.wheelzoom();//Re-enable the zoom
});
});
Why do I have to re-specify the selector inside the loop?