Answers for "javascript queryselector foreach"

9

js foreach querySelectorAll

const allSpanElements = document.querySelectorAll('span');

allSpanElements.forEach((spanElement) => {
  	// Here comes the Code that should be executed on every Element, e.g.
	spanElement.innerHTML = "This Content will appear on every span Element now";
});
Posted by: Guest on March-02-2021
1

loop through html nodelist

const fakeImages = document.querySelectorAll(".fake-image");

	for (var i = 0; i < fakeImages.length; i++) {
	  console.log('fakeImage: ', fakeImages[i]);
	}
                                          
	for (const fakeImage of fakeImages) {
	  console.log('fakeImage: ', fakeImage);
	}                                          
                                          
	for (const fakeImage of fakeImages.entries()) {
	  console.log('fakeImage: ', fakeImage);
	};                                          
                                          
	for (const fakeImage of fakeImages.values()) {
	  console.log('fakeImage: ', fakeImage);
	};
                                          
	for (const fakeImage of fakeImages.keys()) {
	  console.log('fakeImage: ', fakeImage);
	};                                          
                                          
	fakeImages.forEach(fakeImage => {
	  console.log('fakeImage: ', fakeImage);
	});
      
	[...fakeImages].forEach(fakeImage => {
			console.dir(fakeImage);
	});
Posted by: Guest on August-14-2020
0

queryselector get each element

[].forEach.call(
    document.querySelectorAll('.check'),
    function (el) {
        console.log(el);
    }
);
Posted by: Guest on April-14-2021

Code answers related to "javascript queryselector foreach"

Code answers related to "Javascript"

Browse Popular Code Answers by Language