This article mainly introduces the basic idea and implementation code for js to dynamically Delete div elements. For details about how to dynamically load and display the search results during user search, those html elements must be dynamically generated by Ajax. When the user opens the search interface, the system recommends users. When the user searches by condition, the search results are dynamically loaded and displayed. Therefore, JavaScript is used for this purpose. This for loop removes existing forms. Then, a new form object is dynamically generated based on the data in the Ajax request. Be sure to pay attention to the j variable from large to small loop. Otherwise, after deleting the p element, serchResultLenth = serchResult will occur. children. length; length changes (this problem has been explored for a long time before it can be done, remember)
The Code is as follows:
For (var j = serchResultLenth-1; j> = 0; j --){
Var serchChild = document. getElementById (serchResult. children [j]. id );
SerchResult. removeChild (serchChild );
}