I'm new to JavaScript. What I have learnt so far is that we can access html element either through getElementById or querySelector. But I saw a code in which the html element has accessed directly through id but without using getElementById or querySelector .I have tested it. It is working .But I'm unable to understand how it is working. can anyone explain what is going on .It would be a great favor.
<html>
<head>
<title></title>
<script>
document.addEventListener('DOMContentLoaded', function() {
btn.addEventListener('click',()=>{
test.innerHTML="Some value"
alert(txt.value)
})
});
</script>
</head>
<body>
<input type="text" value="Ahtisham" id="txt">
<p id="test">abc</p>
<button id="btn" >Click me</button>
</body>