JQuery Multiple Identifiers

Here is a snippet of the beginning of my code:

var myUpload = $("#upload_link").upload({bla bla bla 

Basically what I'm trying to do is make the same call with several different identifiers ...

I would suggest that this works, but it is not:

 var myUpload = $("#upload_link,#upload_link2,#upload_link3").upload({ 

Any ideas?

+80
javascript jquery
Aug 16 2018-11-11T00:
source share
6 answers

Try the following:

 $("#upload_link,#upload_link2,#upload_link3").each(function(){ $(this).upload({ //whateveryouwant }); }); 
+166
Aug 16 2018-11-11T00:
source share

If you give each of these instances a class that you can use

 $('.yourClass').upload() 
+30
Aug 16 '11 at 13:35
source share

You can use a few id way you wrote:

 $('#upload_link, #upload_link2, #upload_link3') 

However, this does not mean that these identifiers exist in the DOM when executing code. It also does not mean that upload is a legit function. This also does not mean that upload was built in such a way that allows you to use multiple elements in the selected fragment.

upload is a custom jQuery plugin, so you will need to show what happens with upload so that we can help you.

+14
Aug 16 2018-11-18T00:
source share

Make sure the upload plugin implements this.each in it so that it this.each logic for all the relevant elements. It should work perfectly

 $("#upload_link,#upload_link2,#upload_link3").upload(function(){ }); 
+8
Aug 16 2018-11-18T00:
source share

He must. Generally, how do you make multiple selectors. Otherwise, you may not like that you are trying to assign the return values โ€‹โ€‹of three downloads to the same var.

I would suggest using .each or perhaps pushing a return to an array, rather than assigning them to this value.

+4
Aug 16 2018-11-11T00:
source share

This should work, you may need a space after the decimal point.

In addition, the function that you call later must support an array of objects, not just a singleton object.

0
Aug 16 2018-11-11T00:
source share



All Articles