Home > Web Front-end > JS Tutorial > body text

js removeChild blindfold possible errors_javascript skills

WBOY
Release: 2016-05-16 18:45:23
Original
952 people have browsed it

There is a structure:

Copy code The code is as follows:

  • a

  • b

  • c



If you run code 1:
Copy code The code is as follows:

var ul = document.getElementById('demo');
var liList = ul.getElementsByTagName('li');
for (var i = 0; i < = liList.length; i ) {
ul. removeChild(liList[i]);
}

If you were deceived like me, then you will understand the reason after looking at the correct code!
Copy code The code is as follows:

var ul = document.getElementById('demo');
var liList = ul.getElementsByTagName('li');
var lilength = liList.length;
for (var i = 0; i < lilength; i ) {
ul.removeChild( liList[0]);
}
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!