i need to display value of <input>
into the <span>
and when label become empty, change value of span to "Video title". But always i type something into the <input>
and then delete it, the <input>
still have "" value so <span>
display nothing. Thanks for help. (And sorry for my bad english)
Here is my code:
$("#newVideoName").keyup(function(){
var newVideoName = $("#newVideoName").val();
if(newVideoName == ""){
$("#newVideoNameLabel").html("Video title");
}
});
<input type="text" id="newVideoName">
<span id="newVideoNameLabel"></span>
The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .
keydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.
keyup / keydown seem to only work on elements that are present at document. ready . If you are triggering your event from elements that were altered or injected post pageload, these events will not fire.
$("#newVideoName").keyup(function() {
$("#newVideoNameLabel").text(this.value ? this.value : "Video title");
});
http://jsfiddle.net/gZPyQ/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With