I have a function that calls another function. My goal is to pass button as a parameter to another function.
function A(){
var btn = $find("<%=btnX.ClientID %>");
B(btn);
}
function B(*btn parameter here*){
//I need button here
}
You sort of dont even have a issue since it should already work...
function A(){ // var btn = $find("<%=btnX.ClientID %>"); btn = "test" // remove this "test" line B(btn); } function B(button){ //I need button here console.log(button) } A()
It should just work. Do you see any errors there?
function A(){ var btn = $find("<%=btnX.ClientID %>"); B(btn); } function B(button){ // Do with that button whatever you want here. Eg button.style.color = 'cyan'; } A()
Try this with any selector. It should just work
function A(){
var btn = "#btn";
B(btn);
}
function B(button){
// Do with that button whatever you want here. E.g.
var btn = document.querySelector(button);
btn.style.backgroundColor = 'red';
btn.style.color = 'white';
}
A();
function A(){ var btn = "#btn1"; B(btn); } function B(button){ // Do with that button whatever you want here. Eg var btn = document.querySelector(button); console.log(button); btn.style.backgroundColor = 'red'; btn.style.color = 'white'; } A();
<button id="btn0">click button</button> <button id="btn1">click button</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.