Home  >  Article  >  Web Front-end  >  How to delete superior elements in jquery

How to delete superior elements in jquery

青灯夜游
青灯夜游Original
2022-03-10 19:04:282490browse

Deletion method: 1. Use the unwrap() method to delete, the syntax is "$(selector).unwrap()"; 2. Use parent() to get the superior element, and use the remove() method to delete the obtained element. , syntax "$(selector).parent().remove()".

How to delete superior elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery deletes the superior element (parent element)

Method 1: Use the unwrap() method

# The ##unwrap() method removes the parent element of the selected element, but leaves itself (and siblings, if present) in its original position.



	
		
		
		
		
	
    ul (父节点)
  • li (类名为"star"的上一个兄弟节点)
  • li (类名为"star"的上一个兄弟节点)
  • starli (兄弟节点)
  • li (类名为"star"的下一个兄弟节点)
  • li (类名为"star"的下一个兄弟节点)

How to delete superior elements in jquery

Method 2: Use parent() to obtain the superior element, and use the remove() method to delete the obtained element

remove () method removes selected elements, including all text and child nodes. This method also removes data and events from the selected element.



	
		
		
		
		
	
    ul (父节点)
  • li (类名为"star"的上一个兄弟节点)
  • li (类名为"star"的上一个兄弟节点)
  • starli (兄弟节点)
  • li (类名为"star"的下一个兄弟节点)
  • li (类名为"star"的下一个兄弟节点)

选择类名称为“star”的li元素的上级元素

How to delete superior elements in jquery

[Recommended learning:

jQuery video tutorial, web front-end video

The above is the detailed content of How to delete superior elements in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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