Styling the label in an input file type

2

Is there a way to style a label of a certain form only when the input of type file is with a selected file?

    
asked by anonymous 16.08.2016 / 15:33

1 answer

2

I do not know if you can do this with css, you need to track the change event in the input, anyway here is 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>
    
16.08.2016 / 15:46