Mon Feb 12 2018
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

// find all duplicate ids
function show_elements_with_duplicate_ids(){
	const duplicate_ids = new Set();
	const ids_found = new Set();
	const elems_with_ids = Array.from(document.querySelectorAll('*[id]'));
	elems_with_ids.forEach(elem => {
		if(ids_found.has(elem.id)){
			duplicate_ids.add(elem.id);
		}
		else{
			ids_found.add(elem.id);
		}
	});
	const elems_with_duplicate_ids = elems_with_ids.filter(elem => duplicate_ids.has(elem.id));
	console.log(elems_with_duplicate_ids);
}
show_elements_with_duplicate_ids();





// find all imgs without alts
document.querySelectorAll('img:not([alt])');