Frans B Frans B - 1 month ago 5x
Javascript Question

Why wont this on.Click event not work

///// FORM ////
var form = document.getElementById("form");
form.setAttribute("style", "position: relative; margin-bottom: 5%;");

var newButton = document.createElement('button');
var newUl = document.createElement('ul');
var newLi = document.createElement('li');
var newInput = document.createElement('input');
newButton.setAttribute("style", "position: absolute; width: 15%; height: 40px; left: 42%; color: #B00000; background-color: white; font-size: 18px; border: 0px; ");
newButton.innerHTML = "Direct Message";
newButton.onClick = function() {

Is there something wrong with my selection? just want the to work on my button which is newButton created element.


Javascript property names are case-sensitive, it should be newButton.onclick.

Or you could move into the modern age and use addEventListener.

newButton.addEventListener("click", function() {