I am wildly confused by Javascript's ability to handle events out of order. On windows/chrome, the code below outputs to console the object with the class already changed before it has been changed, but then outputting just the class shows the unchanged class. Can someone please explain what rule is governing this? I don't know how to anticipate in what state to expect to see my objects.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Table Schema</title>
</head>
<body>
<a href="#" class="first_class" onclick="checkClass(this)">I am supposed to be first_class!</a>
<script>
function checkClass(obj) {
console.log(obj);
console.log(obj.className);
if (obj.className == 'first_class') {
obj.className = 'second_class';
}
}
</script>
</body>
</html>
<html>