var obj1 = document.getElementById("p");
var obj2 = document.getElementById("btn");
alert(obj1);
alert(obj1);
This Code in JavaScript is returning null. I have both id 'p' and 'btn' in my html as Lable and Button respectively.
I have tried all other ways in my knowledge to solve this problem like
document.getElementById('btn').addEventListener('click', function () {
alert('Click..!!');
});
document.getElementById('btn').onclick = function () {
alert('Click..!!');
};
and others including Jquery but can someone point why it is returing null instead of HTMLObject? Thanks.
UPDATE html as:
<body>
<label id="p">L</label>
<button id="btn" value="Click" >Click</button>
</body>