I came across a problem while trying to select a DOM element inside a callback function using Jquery, I always get undefined value, note that there is nothing wrong with the key variable, the only problem is that Jquery can't seem to select the input element and get its value.
$(".mybutton").on('click', function(){
var key = $(this).attr('key');
__CANVAS.mousemove(function(evt){
var mousePos = getMousePos(__CANVAS2, evt);
$("#x[" + key + "]").val(); // undefined
$("#y[" + key + "]").val(); // undefined
});
});
This is the html
<input id="x['.$key.']" name="x'.$key.'" type="text" value="x'.$key.'" width="50px">
x
<input id="y['.$key.']" name="y'.$key.'" type="text" value="y'.$key.'" width="50px">
y
<button type="button" key="'.$key.'" class="mybutton">Create/Edit</button>
Thanks in advance.