I'm uploading an image using ajax.
i want to make this function to work with class name instead of ids.
$(document).ready(function(){
var button = $('#uploader'), interval;
new AjaxUpload(button, {
action: 'upload.php',
onSubmit : function(file , ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
alert('Error: Only images are allowed');
return false;
} else {
// Image Accepted.
}
},
onComplete: function(file, response){
button.attr("src", response);
}
});
});
in html
<img id="uploader" src="" />
works fine but i want to add more img tags.
please suggest how can i change this function to work with class instead of ids
<img class="uploader" src="" />
<img class="uploader" src="" />
You can read about jQuery class seletor here. I guess you would then use jQuery .each
to loop all buttons or what not.
Try this:
var button = $('.uploader'), interval;
And:
<img class="uploader" src="" />
<img class="uploader" src="" />