Monday, October 23, 2023
HomeSoftware DevelopmentJavaScript closest

JavaScript closest


With regards to discovering relationships between components, we historically consider a top-down method. We are able to thank CSS and querySelector/querySelectorAll for that relationship in selectors. What if we wish to discover a component’s mum or dad based mostly on selector?

To look up the aspect tree and discover a mum or dad by selector, you should utilize HTMLElement‘s closest methodology:

// Our pattern aspect is an "a" tag that matches ul > li > a
const hyperlink = doc.querySelector('li a');
const record = a.closest('ul');

closest seems to be up the ancestor chain to discover a matching mum or dad aspect — the alternative of conventional CSS selectors. You’ll be able to present closest a easy or advanced selector to look upward for!

  • Facebook Open Graph META Tags

    It is no secret that Fb has turn into a significant site visitors driver for every type of internet sites.  These days even giant companies steer shoppers towards their Fb pages as an alternative of the company web sites immediately.  And naturally there are Fb “Like” and “Advocate” widgets on each web site.  One…

  • Send Text Messages with PHP

    Children today, I inform ya.  All they care about is the know-how.  The video video games.  The bottled water.  Oh, and the texting, all the time the texting.  Again in my day, all we had was…OK, I had all of these items too.  However I nonetheless do not get…

  • MooTools Typewriter Effect Plugin Upgrade
  • Truly Responsive Images with responsive-images.js

    Responsive internet design is one thing you hear lots about today. The second I actually began to get into responsive design was a couple of months in the past after I began to understand that ‘responsive’ is not only about scaling your web sites to the scale of your…



Supply hyperlink
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments