var input = div.querySelector("input"); var button = div.querySelector("button"); input.value = "Value for the input"; button.addEventListener("click", function() { alert(input.value); });