Hy,
I have a small problem with jQuery
When I add a new input field, i can't use the click function on it :
var input = $('<input name="image" type="file"/>');
$(this).append(input);
input.click();
Any idea?
Thanks
Hy,
I have a small problem with jQuery
When I add a new input field, i can't use the click function on it :
var input = $('<input name="image" type="file"/>');
$(this).append(input);
input.click();
Any idea?
Thanks
If you attach a click event handler to the new input
, it will work fine:
var input = $('<input name="image" type="file"/>');
input.click(function() {
//Do something
});
$(this).append(input);
input.click();
If on the other hand you want the new input
to pick up an event handler that's been defined previously, you will have to use live
when you attach the event initially (this example attaches a click event handler to all input
elements, including ones that get added to the DOM later, like yours):
$("input").live("click", function() {
console.log("other clicked");
});