When it comes to finding relationships between elements, we traditionally think of a top-down approach. We can thank CSS and querySelector
/querySelectorAll
for that relationship in selectors. What if we want to find an element’s parent based on selector?
To look up the element tree and find a parent by selector, you can use HTMLElement
‘s closest
method:
// Our sample element is an "a" tag that matches ul > li > a const link = document.querySelector('li a'); const list = a.closest('ul');
closest
looks up the ancestor chain to find a matching parent
element — the opposite of traditional CSS selectors. You can provide closest
a simple or complex selector to look upward for!
CSS Filters
CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let’s have…
Create Custom Events in MooTools 1.2
Javascript has a number of native events like “mouseover,” “mouseout”, “click”, and so on. What if you want to create your own events though? Creating events using MooTools is as easy as it gets. The MooTools JavaScript What’s great about creating custom events in MooTools is…