Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check whether a node is editable or not in TypeScript
/**
* Checks whether the passed in node is editable or not.
* An editable node is one that returns true to isContentEditable or has a tag name as
* any one of the following:
* "textarea", "input", "text", "email", "number", "search", "tel", "url", "password"
*
* @param node the node to check
* @return true if the node is editable and false otherwise
*/
function isEditable(node: Node): boolean {
let element = node as HTMLElement;
let nodeName: string = element.nodeName.toLowerCase();
let editables = ["textarea", "input", "text", "email", "number", "search", "tel", "url", "password"];
return (element.isContentEditable || (element.nodeType === Node.ELEMENT_NODE && editables.contains(nodeName)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.