I have a file input inside a div, and I would like to access to it, but the file input has no id.
var el = $("#hey > :file");
console.log(el);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="something" id="hey">
<div class="remote"></div>
<input type="file">
</div>
But I get a lot of elements, I would like to know if it's possible to do without jQuery.
<input type="file"> can be matched by the selector input[type="file"], so use that next the #hey >.
You don't need jQuery, querySelector works just fine.
var el = document.querySelector('#hey > input[type="file"]');
console.log(el);
el.onchange = () => {
console.log(el.files);
};
<div class="something" id="hey">
<div class="remote"></div>
<input type="file">
</div>
You can use document.querySelector() to get first match element, or if you need list of all elements use document.querySelectorAll()
var el = document.querySelector('#hey > input[type="file"]');
console.log(el);
<div class="something" id="hey">
<div class="remote"></div>
<input type="file">
</div>