JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 6 SetAttribute

wk5_setAttribute

Pokemon

  • Chimchar
  • Mudkip
  • Squitle
  • Pikachu
  • Groudon
		
001function getChildNodes(elem) {
		
002	let textOutput = '';
		
003	const ulElement = document.getElementById(elem); // Get element with ID borough 
		
004	for (let i = 0; i < ulElement.children.length; i++) { // Iterate through its child nodes
		
005		console.log(ulElement.children[i].innerText)// Write child nodes to console
		
006		textOutput += '<p><a>'+ ulElement.children[i].innerText+'</a></p>';	
		
007	}
		
008	//const linksNav = document.getElementById('links')
		
009	const linksNav = ulElement.parentElement.parentElement.children[1]; 
		
010	linksNav.innerHTML = textOutput;
		
011	for(let i = 0; i<linksNav.children.length; i++)
		
012	{
		
013		linksNav.children[i].firstElementChild.setAttribute('href', linksNav.children[i].innerText.toLowerCase() +'.html');
		
014	}	
		
015}
		
016
		
017window.onload = function() { 
		
018	getChildNodes('pokemon');
		
019}