Label stylization in a file type input

Asked

Viewed 137 times

2

There is a way to style a label in a certain way only when the input of the kind file is with a selected file ?

1 answer

2


I don’t know if you can do this just with css, you need to track the event change no input, anyway here’s a solution using javascript:

function change_label() { // aqui coloca todas as mudanças a acontecer nos elementos que quiser
  var label_file = document.getElementById("label-file");
  label_file.className = "file_on";
  label_file.children[0].innerHTML = 'JÁ EXISTE FICHEIRO';
}
.file_on {
 color:red; 
}
<label id="label-file" for="file-inp"><span>NÃO EXISTE FICHEIRO</span><br>
  <input onchange="change_label();" id="file-inp" type="file">
</label>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.