Why doesn't this text run?

A textbook gives an example. This can refer to the caller in the called function.
the following this is div

<script>
stat = function(){
    var taoId = document.getElementById("div2");
    taoId.onmouseover = function{
        this.align = "right";
    }
    taoId.onmouseout = function{
        this.align = "left";
    }
}
window.onload = stat;
</script>
<div id = "div2"></div>

Why doesn"t this example work? No text escape effect?

Apr.11,2021

. Because your function
function () {} is missing parentheses


What does the align in

this.align stand for
?

clipboard.png


1. There is a problem function () {} written in the method definition-- missing parentheses
2. Generally, we don't do this directly. We usually change the style by removing or and adding class

.
Menu