Home >Web Front-end >JS Tutorial >Two different ways to get parent elements and delete child elements using js and jquery_javascript skills
var obj=document.getElementById("id"); What you get is the dom object. Use the js method when operating on the object
var obj=$("#id"); What you get is a jquery object. Use the jquery method when operating on this object
1. Traverse the objects obtained above
(1).js method for(vat i=0;j (2).jquery method $(“#id”).each(function(){ $(this) to get the corresponding element}); 2. Get the parent element of the element that meets the condition (1).js method: var o=obj[i].parentNode (2).jquery method: var o=$(this).parent() 2. After getting the parent element, you can delete the child elements of the parent element (1).js method: o.removeChild(obj[i]); (2).jquery method: o.empty()