+ 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();

6th Dec 2024, 3:01 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
14 Antworten
+ 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(); };
6th Dec 2024, 4:16 PM
BroFar
BroFar - avatar
+ 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.
6th Dec 2024, 5:44 PM
BroFar
BroFar - avatar
+ 4
Isn't it green?Captain Thunder ⚡
7th Dec 2024, 7:53 AM
Daniel
Daniel - avatar
+ 3
Thanks BroFar
6th Dec 2024, 6:36 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 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
6th Dec 2024, 5:12 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 2
Let Brofar be the best comment by giving him the yellow tick
7th Dec 2024, 3:55 AM
Captain Thunder ⚡
Captain Thunder ⚡ - avatar
6th Dec 2024, 3:01 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
6th Dec 2024, 3:06 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 1
Hi
7th Dec 2024, 9:40 AM
VISHALEESWARAN K
VISHALEESWARAN K - avatar
+ 1
Sorry Daniel
7th Dec 2024, 9:53 AM
Captain Thunder ⚡
Captain Thunder ⚡ - avatar
7th Dec 2024, 9:59 AM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 1
Who can teach me code C ++? I have exam
7th Dec 2024, 12:11 PM
Liliana Agiu
+ 1
Liliana Agiu you can learn it here on solo learn 😊
7th Dec 2024, 12:39 PM
IFEANYICHUKWU HENRY OKWOR
IFEANYICHUKWU HENRY OKWOR - avatar
+ 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.
7th Dec 2024, 11:51 PM
GRU ( ? )
GRU ( ? ) - avatar