I just came across a question that was very bad in the beginning as it was more or less a "give me the code" request. The question received two answers, one of which is
var input = document.querySelector('input');
input.onkeyup = function(){
var showClass = 'show';
var label = input.previousElementSibling;
if(this.value !== '')
{
label.classList.add(showClass);
}
else
{
label.classList.remove(showClass);
}
}
The other answer said literally "yes it's possible, but we won't write the code for you".
After that, it took a few minutes for the OP to edit their question:
But I'm missing something. Only the first label in the form works. So far I've got:
var input = document.querySelector("input");
input.onkeyup = function(){
var showClass = "show";
var label = document.querySelector("label");
if(this.value !== '')
{
label.classList.add(showClass);
}
else
{
label.classList.remove(showClass);
}
}
I've left a comment, and got below response
Apart from that this is, IMHO outrageous, how is it with SO's license? I know that you need to attribute a post you've taken from here, but how is it if you steal code from here and post it here again, saying it's your code?