user2507818
user2507818

Reputation: 3047

issue with codes execution order in javascript

test.php:

<script type="text/javascript" src="test.js"></script>
<body onload="init()">

test.js:

var req;
var isIE;
var completeField;
var completeTable;
var autoRow;
function init() {
    completeField = document.getElementById("complete-field");
    completeTable = document.createElement("table");
    console.log(completeTable);
    completeTable.setAttribute("class", "popupBox");
    completeTable.setAttribute("style", "display: none");
}

In console, it shows:

<table class="popupBox" style="display: none"></table>

Question:

completeTable.setAttribute runs after console.log(completeTable);, how come, it still shows the table attributes?

Upvotes: 0

Views: 32

Answers (1)

Pouki
Pouki

Reputation: 1664

It is because console.log takes the state of the actual object when you look into the logged object... Try alert(completeTable.getAttribute("style")) instead and you will see there is no style yet.

Upvotes: 3

Related Questions