Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Last active December 21, 2016 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniel-Hug/7349e15d04384c841a421b4f071f9603 to your computer and use it in GitHub Desktop.
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
// 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