After getting the element by using document.getElementById() you can change the element’s content or attributes. You can also add an event listener to the element. // to change the content inside the HTML element par1.innerHTML = “New text of paragraph with id p1”; //to change the attributes values of the element par1.setAttribute(“style”,”color:red”); par1.style.color = “red”; //another way img1.src = “Kuwait.jpg”; //changing the image source for an img element with id = img1 var imagesrc = img1.src; //getting the value of the attribute as a string //add an event listener to an element par1.addEventListener(“click”, myfunction, false); document.getElementById() method
Click any button and I will tell you which button you clicked Button 1 Button 2
Adding elements to an array The length property provides an easy way to append new elements to an array without using the push() method. Try it
Adding elements to an array
Multidimensional Arrays To identify a particular two-dimensional multidimensional array element Specify the two subscripts By convention, the first identifies the element’s row, and the second identifies the element’s column In general, an array with m rows and n columns is called an m-by-n array Two-dimensional array element accessed using an element name of the form a[ i ][ j ] a is the name of the array i and j are the subscripts that uniquely identify the row and column Multidimensional arrays are maintained as arrays of arrays var a = [[1,2,3], [4,5,6],[7,8,9]];
20 Fig | Two-dimensional array with three rows and four columns.