Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121970339
closest.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 15, 03:27
Size
599 B
Mime Type
text/x-java
Expires
Thu, Jul 17, 03:27 (2 d)
Engine
blob
Format
Raw Data
Handle
27419444
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
closest.js
View Options
import
matches
from
'./matches'
;
/**
* Returns the closest parent element that matches a given selector.
*
* @param node the reference element
* @param selector the selector to match
* @param stopAt stop traversing when this element is found
*/
export
default
function
closest
(
node
,
selector
,
stopAt
)
{
if
(
node
.
closest
&&
!
stopAt
)
node
.
closest
(
selector
);
var
nextNode
=
node
;
do
{
if
(
matches
(
nextNode
,
selector
))
return
nextNode
;
nextNode
=
nextNode
.
parentElement
;
}
while
(
nextNode
&&
nextNode
!==
stopAt
&&
nextNode
.
nodeType
===
document
.
ELEMENT_NODE
);
return
null
;
}
Event Timeline
Log In to Comment