{"id":16326676,"url":"https://github.com/chrisyip/closest-element","last_synced_at":"2025-05-14T22:12:16.766Z","repository":{"id":57200621,"uuid":"61440850","full_name":"chrisyip/closest-element","owner":"chrisyip","description":"Find the closest element that matches a selector or an element","archived":false,"fork":false,"pushed_at":"2017-08-11T02:46:49.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T14:05:42.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisyip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-18T15:50:26.000Z","updated_at":"2016-06-18T16:17:12.000Z","dependencies_parsed_at":"2022-09-16T15:10:26.006Z","dependency_job_id":null,"html_url":"https://github.com/chrisyip/closest-element","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fclosest-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fclosest-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fclosest-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fclosest-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisyip","download_url":"https://codeload.github.com/chrisyip/closest-element/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235711,"owners_count":22036966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T23:09:16.487Z","updated_at":"2025-05-14T22:12:16.742Z","avatar_url":"https://github.com/chrisyip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# closest-element\n\nFind the closest element that matches a selector or an element\n\n## Usage\n\n```js\nclosest(element, selectorOrElement, [rootElement = null, [excludeSelf = false]])\n```\n\n`element`, the first element.\n\n`selectorOrElement`, a string of selector expression or an element to match elements against.\n\n`rootElement`, if matches current element, this function will stop traversing up.\n\n`excludeSelf`, whether skip self from matching.\n\nReturns matched element, or `null` if no element found.\n\nExample:\n\n```html\n\u003cnav\u003e\n  \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"#\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#\"\u003eContact Us\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/nav\u003e\n```\n\n```js\nimport closest from 'closest-element'\n\nclosest(document.querySelector('ul'), 'ul') // returns \u003cul\u003e\nclosest(document.querySelector('ul'), 'ul', true) // returns null\nclosest(document.querySelector('a'), 'ul li', document.querySelector('li')) // \u003cli\u003e\nclosest(document.querySelector('a'), 'ul', document.querySelector('li')) // false\nclosest(document.querySelector('a'), document.querySelector('nav')) // \u003cnav\u003e\n```\n\n### Files\n\n```\nsrc/\n  - cloest.js // in es6\n\ndist/\n  - closest.cjs.js // CMD\n  - closest.es6.js // ES6 module, compiled with Buble\n  - closest.js     // UMD\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fclosest-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisyip%2Fclosest-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fclosest-element/lists"}