I am building a website, and I want a div to go from display: none; to display: block; as soon as a user starts typing in the first input.
I know something about jquery, but I have no idea on how to do this.
Can anyone help me?
I am building a website, and I want a div to go from display: none; to display: block; as soon as a user starts typing in the first input.
I know something about jquery, but I have no idea on how to do this.
Can anyone help me?
I'd use the keyup or keydown events :
$('input').on('keyup', function() {
if ( !$('div').is(':visible') ) $('div').show();
});
oninput in HTML 5 compatible browsers this would get these types of input.input event has really poor support and bugs all over the place, that's why noone uses it.input event was better supported and worked satisfactory it would be great. Today it's common to do $('input').on('keyup paste change', function() { ...}); etc. to capture many events, the input event would make it easier, but as of today it barely works in the most modern browsers, so using it on a production website is not an option for most people.According to this answer here : https://stackoverflow.com/a/2826423/686036, you would want to use the HTML 5 syntax of oninput. This would take care of auto-fill or right click paste functions.
You're input would look like this :
<input id="myInput" type="text" />
And the JavaScript :
var myInput = document.getElementById("myInput");
myInput.addEventListener('input', myFunction(), true);
Or using JQuery if this is desired :
$('#myInput').bind('input', function() {
alert('User clicked on "foo."');
});
Now that HTML 5 is a W3C candidate recommendation, it should/will be implement in most of the new releases of browsers, if it is not yet implemented.
oninput. But will change the answer to reflect this.oninput.You can probably use the change event with jquery :
$('input').change(function() {
$('#your-div').show();
});
keypress event. change only fires after focus is lost.