onclick event for all inputs in a form?
DANG IT. There is no fade()
- answer found.
I want to have it so that whenever someone clicks on a form input, a div fades away.
$( '#form_id' ).find( 'input' ).click(function() {
$( '#div_to_fade_away' ).fade();
});
Why wouldn't that wo开发者_如何学编程rk? Similar question. Appears to work for this use?
You need the fadeOut()
(docs) method instead of .fade()
, and make sure the DOM is loaded.
$(function() {
$( '#form_id' ).find( 'input' ).click(function() {
$( '#div_to_fade_away' ).fadeOut();
});
});
Wrapping your code with $(function() { /* your code */ });
is a shortcut for calling jQuery's ready()
(docs) method.
While I think there's the more to this question than you stated, the reason that your posted jQuery doesn't work is that there is no fade()
method. You can, however, use fadeOut()
.
精彩评论