I found that code on internet and it works fine to create a button
document.write(nomedispositivo)
var r=$('<input/>').attr({//início botão
type: "button",
id: "field" ,
value: "Liga",
But if I insert the line: onclick:switchLED() where switchLED is a function the button not appear where is the problem?
document.write(nomedispositivo)
var r=$('<input/>').attr({//início botão
type: "button",
id: "field" ,
value: "Liga",
onclick:switchLED()
asked Mar 15, 2015 at 13:28
Roberto Bahia
1051 gold badge2 silver badges11 bronze badges
1 Answer 1
Why add the click handler this way in the first place? You're using jQuery, so use jQuery. Just add the handler to the jQuery element you already have:
var r=$('<input/>').attr({
type: "button",
id: "field" ,
value: "Liga"
});
r.click(switchLED);
Since r is a jQuery element, you can use the click(function) function to add a function reference to that element's click event handler.
answered Mar 15, 2015 at 13:32
David
221k42 gold badges249 silver badges339 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
onclick:"switchLED()"