+ 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;
6th Jun 2021, 10:22 AM
JaScript
JaScript - avatar
+ 2
7th Jun 2021, 7:08 AM
JaScript
JaScript - avatar
+ 1
Alternatively, you can directly access the "id" attribute value as a global variable: if(abc.value == 10)
6th Jun 2021, 10:53 AM
Solo
Solo - avatar
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>"
7th Jun 2021, 8:51 AM
Solo
Solo - avatar