querySelector("#ID1, #ID2, ID#3")¿Existe la posibilidad de poner en un solo querySelector algunos ID?
querySelectorAll se puede usar para apuntar a múltiples selectores.
document.querySelectorAll("#div1, .div2, h3");El método querySelector() devuelve el primer elemento que coincide con uno o más selectores CSS especificados en el documento.
Tenga en cuenta que para devolver todas las coincidencias, use el método querySelectorAll() en su lugar.
ejemplo
<div class="bar">.first </div> <div class="bar">.second</div> //get the first element with class bar let firstElement = document.querySelector('.bar'); //log the first match console.log(firstElement) //get all elements with class bar let allElements = document.querySelectorAll('.bar') //You can use any common looping statement to access the matches allElements.forEach(function(elements){ console.log(elements); }); /* querySelector("#ID1, #ID2, ID#3") *select element matches #ID1 *select element matches #ID2 *select element matches #ID3 **/ //select elements matches specified selectors #id1 , #id2 , #id3 and use any common looping statement to access them let allMatchesId = document.querySelectorAll('#id1 , #id2 , #id3'); allMatchesId .forEach(function(elements){ console.log(elements); });lea los documentos aquí en MDN https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
Simple ! Utilice el siguiente código.
document.querySelectorAll('#id1, #id2 , #id3'); Esto devolverá la nodelist que puede iterar y puede realizar las acciones que desee.