SoFunction
Updated on 2025-04-05

vue recursively obtains element instance of parent element

Use recursion to find the parent element, know to find the desired element, and then return

 getParentTag(startTag) {
   var self = this;
   // Whether the incoming tag is a DOM object   if (!(startTag instanceof HTMLElement)) return;
   // Whether the parent tag is a body, it stops returning to the set, otherwise continues   let nodeName = "";
   if () {
    nodeName =  ?  : "";
   } else {
    return;
   }
   if ("BODY" !== nodeName) {
    if (nodeName == "TD") {
     return ;
    } else {
     if () {
      return ();
     } else {
      return false;
     }
    }
   }
  }

Calling functions

();

Supplementary knowledge:How to get sibling elements, children elements, parents elements (DOM operations)

I won't say much nonsense, please read the code~

<button @click = “clickfun($event)”>Click</button>
 
methods: {
clickfun(e) {
// is the element you are currently clicking// It is the element of the event you bind  #Get the previous element of the click element  
  #Get the first child element of the click element  
  # Get the next element of the click element  
  # Get the element with id string in the click element  ("string")
  # Get the string attribute of the click element  ('string')
  # Get the parent element of the click element  
  # Get the HTML value of the first child element of the previous element of the click element  
 
  }
    },

The above example of vue recursively obtaining element elements is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.