Last active
December 21, 2016 05:32
-
-
Save Daniel-Hug/7349e15d04384c841a421b4f071f9603 to your computer and use it in GitHub Desktop.
JS function: check if element can have child nodes, i.e. does it have an end tag? Source: http://stackoverflow.com/a/16130626/552067
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check if element can have child nodes | |
var canHaveChildren = (function() { | |
var noChildren = { | |
input: 1, | |
meta: 1, | |
br: 1, | |
link: 1, | |
img: 1, | |
hr: 1, | |
area: 1, | |
base: 1, | |
col: 1, | |
param: 1, | |
wbr: 1, | |
track: 1, | |
source: 1, | |
embed: 1, | |
command: 1, | |
keygen: 1 | |
}; | |
return function canHaveChildren(tagName) { | |
tagName = tagName.toLowerCase(); | |
return !noChildren[tagName]; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment