Here is my issue:
I am creating dynamically a button with an onclick function like this:
$("#test).html('<input type="button" value="Close" onclick="remove('+param1+','+param2+');" />');
The parameters are well read but the function is not trigger, and I've got this error message: "bob is not defined" when bob is the string value of the param1.
Apparently it seems that bob is read as a variable when it should be read as a string, but I don't understand why.
Thanks much for your help!
I can suggest you this
The key here is the javascript closure. As you can see there a link called
lnkAdder
. It is responsible to add anew item into the container. On click it appends a new item into the container. While appending you use jQuery API and create a new element, add attributes and add event listener. In the event listener body you copy the value into an internal variable. They use it as appropriate.That's because this string right here:
Will look like this in the end:
You probably want it to look like this:
So change it to this:
You could also do this:
Edit: I also noticed that you were missing one " from your $()-call:
$("#test)
should be$("#test")
.