this is the link of my first project
https://codepen.io/newemail/pen/EJMaop?editors=0011
google console say Cannot read property ‘appendChild’ of null
then inspected the HTML i found that
<section id="a b c d e f g h i j k l m n o p q r s t u v w x y z-section"></section>
and i was expecting
<section id="a-section"></section>
<section id="b-section"></section> and so on
can any one help
let alphabetsArr = letterIndexList.innerText.split("\n");
This line isn’t doing what you think it’s doing. If you console.log(alphabetsArr)
you’ll see that it is just
["A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"]
.
i already know that it is an array
i expecting from the for loop to loop through it and assign
alphabetsArr[i].toLowerCase() + "-section"
to the sectionElement.id
and then append each section with its id to divMainId
Look carefully at the array you’re creating. It’s not the array that you want.
Hint: The loop is doing exactly what you want it to do.
1 Like
i figured that now. thank you
Congrats on tracking down the issue! Happy coding.
1 Like