JQuery key input value

I need to map the <input> value to <span> , and when the label becomes blank, change the range value to “Video title”. But I always enter something into <input> and then delete it, the value of <input> still has the value "", so <span> does not display anything. Thanks for the 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> 
+4
source share
1 answer
 $("#newVideoName").keyup(function() { $("#newVideoNameLabel").text(this.value ? this.value : "Video title"); }); 

http://jsfiddle.net/gZPyQ/

+4
source

All Articles