Generalize support for events in Dom element maker

This commit is contained in:
Tissevert 2022-07-25 21:13:15 +02:00
parent a74b0cc480
commit 0d7f180ce2

View file

@ -22,11 +22,13 @@ function make(tag, properties, children) {
case "maxlength": case "maxlength":
e.setAttribute("maxlength", value); e.setAttribute("maxlength", value);
break; break;
case "onClick":
e.addEventListener("click", value);
break;;
default: default:
e[key] = value; var matched = key.match(/on([A-Z]\w+)/);
if(matched) {
e.addEventListener(matched[1].toLowerCase(), value);
} else {
e[key] = value;
}
} }
} }
for(var i = 0; i < children.length; i++) { for(var i = 0; i < children.length; i++) {