Input accept images

Why does this not add “accept” attribute to input field?

var input = $("<input>").attr(“type”,“file”).attr(“name”,“images”).attr(“class”,“uploader”).attr(“id”,“img” + nextInt).attr(“accept”, “images/jpg, images/jpeg”);

Is nextInt defined anywhere?


var nextInt = 3;
var input = $("input").attr("type","file").attr("name","images").attr("class","uploader").attr("id","img" + nextInt).attr("accept", "images/jpg, images/jpeg");

Yes it is a defined value, works perfectly apart from the attr(accept) bit

Seems to work for me with the correct quote tags in place.

Devtools shows this:

<input type="file" name="images" class="uploader" id="img3" accept="images/jpg, images/jpeg">

Not working on my browser using your test. (firefox)

.attr("accept", ".jpg,.jpeg")

or to accept any image file use:
.attr("accept", "image/*")

1 Like

Yep that worked!! Cheers

Well spotted :slight_smile:

I only checked that the accept attribute was added and not that the value was correct :frowning: