New course! Every coder should learn Generative AI!
Try a free lesson0
Why the desired value not showing ?
I want to display welcome but that is not displayed. Why ? https://code.sololearn.com/WheMqexK9z4o/?ref=app
6 Answers
+ 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)
+ 1
JaScript Thanx friend.
0
Vasiliy , Does abc.value assigns all var values ?
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>"