You may use closest()
in modern browsers:
var div = document.querySelector('div#myDiv');
div.closest('div[someAtrr]');
Use object detection to supply a polyfill or alternative method for backwards compatability with IE.
More Related Contents:
- How do I check if an element is hidden in jQuery?
- Why does jQuery or a DOM method such as getElementById not find the element?
- Detect element content changes with jQuery
- How can I select an element by name with jQuery?
- When does reflow happen in a DOM environment?
- Firing event on DOM attribute change
- jQuery object and DOM element
- Javascript get XPath of a node
- How to resolve the C:\fakepath?
- How to expose IFrame’s DOM using jQuery?
- How can I simulate a click to an anchor tag?
- How to get the element clicked (for the whole document)?
- Browser-independent way to detect when image has been loaded
- Can I load an entire HTML document into a document fragment in Internet Explorer?
- How to check if an embedded SVG document is loaded in an html page?
- Get selected text position and place an element next to it
- How do I monitor the DOM for changes?
- change html text from link with jquery
- “Cut and Paste” – moving nodes in the DOM with Javascript
- How to reference the caller object (“this”) using attachEvent
- forEach method of Node.childNodes?
- Get elements from page.evaluate in Puppeteer? [duplicate]
- Getting HTML elements by their attribute names
- Getting the text from a drop-down box
- Display DIV at Cursor Position in Textarea [duplicate]
- Get immediate first child element
- Is there a way to know if a link/script is still pending or has it failed
- What’s the difference between a jQuery object and a DOM element? Difference between .get() and .index()?
- In web browsers, what’s the difference between onblur and onfocusout?
- Create a table in SVG