siblingpastry,
@siblingpastry@mastodon.world avatar

Saturday fun -- a little helper function for closest() that handles the possibility of the input being a text node:

const getClosest = (node, query) => {  
 if(!node) {  
 return null;  
 }  
 while(node.nodeType !== Node.ELEMENT_NODE) {  
 if(!(node = node.parentNode)) {  
 return null;  
 }  
 }  
 return node.closest(query);  
};  
  • All
  • Subscribed
  • Moderated
  • Favorites
  • javascript
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • khanakhh
  • InstantRegret
  • Youngstown
  • ngwrru68w68
  • slotface
  • rosin
  • tacticalgear
  • mdbf
  • kavyap
  • modclub
  • JUstTest
  • osvaldo12
  • ethstaker
  • cubers
  • normalnudes
  • everett
  • tester
  • GTA5RPClips
  • Leos
  • cisconetworking
  • provamag3
  • anitta
  • megavids
  • lostlight
  • All magazines