+ 1
Please help me call this
How can I call the ve() function directly in external js without calling it in html with onclick I had already written my id in html alert("There is inculsion of js in this code"); function bel(){ let a = prompt("your password"); console.log(a) } function ve(){ let b = document.getElementById("cok"); b.style.color='red'; } ve();
14 odpowiedzi
+ 7
IFEANYICHUKWU HENRY OKWOR
window.onload = function() {
alert("There is inculsion of js in this code");
function bel(){
let a = prompt("your password");
console.log(a)
}
function ve() {
let b = document.getElementById("cok");
if (b) { // Check if element exists
b.style.color = 'red';
} else {
console.error("Element with ID 'cok' not found");
}
}
ve();
};
+ 4
just move onload to enclose the function you want to use on loading the window
alert("There is inculsion of js in this code");
function bel(){
let a = prompt("your password");
console.log(a)
}
window.onload=function(){
function ve(){
let b = document.getElementById("cok");
b.style.color='red';
}
ve();
}
Nothing is impossible with God
nice closure.
+ 4
Isn't it green?Captain Thunder ⚡
+ 3
Thanks BroFar
+ 2
BroFar thanks
but what is window.onload
also if I add that to my code the bel() function on line 19 will not work
+ 2
Let Brofar be the best comment by giving him the yellow tick
+ 1
+ 1
Hi
+ 1
Sorry Daniel
+ 1
VISHALEESWARAN K hello
+ 1
Who can teach me code C ++?
I have exam
+ 1
Liliana Agiu you can learn it here on solo learn 😊
+ 1
Are you trying to call a function without clicking from your HTML?
function bel(){
var a = prompt("your password")
console.log(a)
ve(a )
}
function ve(valu){
var b = document.getElementById("cok")
if(!valu){
b.style.color="red"
}else{
console.error("Oops bad");
}
}
If I misunderstood your question, please repeat it with more details.