To select multiple elements on a HTML page you need the document. querySelectorAll()! Put your selector in and you will get all the elements.
Two selectors: visible and: hidden are also available in JQuery.
In jQuery, you can use the . length property to check if an element exists. if the element exists, the length property will return the total number of the matched elements. To check if an element which has an id of “div1” exists.
Try this:
$("#upload_link,#upload_link2,#upload_link3").each(function(){
$(this).upload({
//whateveryouwant
});
});
If you give each of these instances a class you can use
$('.yourClass').upload()
You can use multiple id
's the way you wrote:
$('#upload_link, #upload_link2, #upload_link3')
However, that doesn't mean that those ids exist within the DOM when you've executed your code. It also doesn't mean that upload
is a legitimate function. It also doesn't mean that upload
has been built in a way that allows for multiple elements in a selection.
upload
is a custom jQuery plugin, so you'll have to show what's going on with upload
for us to be able to help you.
Make sure upload
plugin implements this.each
in it so that it will execute the logic for all the matching elements. It should ideally work
$("#upload_link,#upload_link2,#upload_link3").upload(function(){ });
it should. Typically that's how you do multiple selectors. Otherwise it may not like you trying to assign the return values of three uploads to the same var.
I would suggest using .each
or maybe push the returns to an array rather than assigning them to that value.
That should work, you may need a space after the commas.
Also, the function you call afterwards must support an array of objects, and not just a singleton object.
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