I am very new to Javascript and was wondering why the following code will not work.
var p = document.createElement("p");
p.onmouseover = (function() {
this.style.cursor='pointer';
})();
Basically, I just want the cursor to change to pointer when the user hovers over this dynamically create paragraph element.
Thank you.
You are invoking the function by putting
()at the end. Try this instead:and here’s a working demo.