Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label doesn't work

Tags:

html

css

I have this code:

.hidden_element {
  height: 1px;
  width: 1px;
  overflow: hidden;
}
<form action="">
  <label for="file">
    <button type="button" class="button red">Choose File</button>
  </label>
  <div class="hidden_element">
    <input type="file" name="video" id="file" />
  </div>
</form>

The problem is when I click choose file nothing happens.

like image 872
sdfds dffdsf Avatar asked Oct 30 '22 11:10

sdfds dffdsf


1 Answers

Change your button like <button type="button" onclick="document.getElementById('file').click()" class="button red">Choose File</button>

.hidden_element {
  height: 1px;
  width: 1px;
  overflow: hidden;
}
<form action="">
  <label for="file">
    <button type="button" onclick="document.getElementById('file').click()" class="button red">Choose File</button>
  </label>
  <div class="hidden_element">
    <input type="file" name="video" id="file" />
  </div>
</form>
like image 70
Shijin TR Avatar answered Nov 15 '22 07:11

Shijin TR