I am new to programming and have a question regarding HTML elements with id attributes. My question is - if an HTML element has an id attribute, is the value of the id attribute readily usable without defining it in JavaScript? Here is an example to make this more clear:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<input type="checkbox" id="mycheckbox" checked />
<input type="radio" id="myradio" checked />
<p id="test">
p tag too.
</p>
<script>
if(mycheckbox.checked) {
alert("How does this work? Are there more pre-defined stuff (varaibles?) like this one?");
}
if(myradio.checked) {
alert("Another example with radio");
}
alert(test.innerHTML);
</script>
</body>
I have read some books on JavaScript and none have given this shortcut method (if it is one) of working with HTML elements.
Thank you in advance.