I have in an html page a select element with an id="a" (for example). I have a function called f(). when I write
$("#a").on("change",f);
it works, meaning every time I change the selected value in the drop down list the function f() is called.
I want to clone this select in another place in the page. I have this code:
var oldSelect=$("#a")
var newSelect=oldSelect[0].cloneNode(true);
newSelect.id="b";
$("#b").on("change",f);
and when I change the selected value in the new dropdown list, the function f() isn't called.
I tried debugging it using the chrome's devTools and it apears that $("#a") is kind of an array length 1 that in the first place has the select itself. But $("#b") doesn't have the "0" property containing the select itself.
Does anyone know why does it happen? how can I clone a select element with all its options and callbacks?