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

Basic ideas and implementation code for dynamically deleting div elements in js_javascript skills

WBOY
Release: 2016-05-16 16:49:21
Original
1117 people have browsed it

When doing user searches, because the search results need to be dynamically loaded and displayed, those html elements must be dynamically generated by Ajax. When the user opens the search interface, there are users recommended by the system. When the user searches according to conditions, the search results are dynamically loaded and displayed. So consider using js to do it. This for loop removes the existing form. Then dynamically generate new form objects based on the data requested by Ajax. Be sure to pay attention to the j variable looping from large to small, otherwise, deleting the div element will cause the length of serchResultLenth=serchResult.children.length; to change (this problem took a long time to figure out, remember)

Copy code The code is as follows:

for(var j=serchResultLenth-1;j>=0;j--){
var serchChild=document.getElementById(serchResult.children[j].id);
serchResult.removeChild(serchChild);
}

Related labels:
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