0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

logging primitive values will always print the value at the time of logging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.