Js and jquery are two different ways to get the parent element and delete the child element

  • 2020-03-30 01:18:00
  • OfStack

Var obj = document. GetElementById (" id "); What you get is a dom object, which you manipulate using the js method

Var obj = $(" # id "); You get a jquery object, and you use jquery methods when you manipulate that object

1. Iterate over the objects obtained above

(1). Js method   For (VAT I = 0; J< Obj. Length; I ++){obj[I] to get a corresponding element}

(2). The jquery method   $(" #id ").each(function(){$(this) to get the corresponding element};

2. Gets the parent of the element that satisfies the condition

(1). Js method: var o=obj[I]. ParentNode

(2). Jquery method: var o=$(this).parent()

2. After obtaining the parent element, you can delete the child element of the parent element

(1). Js method: o.removeChild(obj[I]);

(2). Jquery method: o.epty ()


Related articles: