get id of element javascript

JavaScript
var element = document.getElementById("oldID");
element.id = "newID";var element = document.getElementsByTagName("div")[0];
var id = element.id;
Source

Also in JavaScript: