+ 6
* getElementById returns the element that has the ID attribute. In add you need to call its value as follows:
var x = document.getElementById("abc").value;
+ 2
Harsh Kishore welcome
+ 1
Alternatively, you can directly access the "id" attribute value as a global variable:
if(abc.value == 10)
0
Yes all.
Your function can be abbreviated to:
function myFunction() {
if (abc.value <= 10) {
def.textContent = "Welcome!";
} else {
def.textContent = "Sorry! Try Again!";
}
}
👇ES6:
myFunction=()=>{
def.textContent = abc.value <= 10
?"Welcome!"
:"Sorry! Try Again!";
}
Feel free to experiment with your code after making a copy, or comment out first option.
For example, you can replace textContent with innerText, and if you replace it with innerHTML, then you can insert tags into the text:
def.innerHTML = "<b>Welcome!</b>"