JavaScript Make inputfield clickable everywhere inside button-div make input field clickable,make input field not clickable,make

I´m implementing a FileUpload and have created <div> with bootstrap button class to make it look better.

But since I did this the input is just clickable at a specific position (above 'aufnehmen').

Can someone tell me how to make the Window open when clicking anywhere on the div?

Here is a fiddle that demonstrates my problem.

.btn-lg{
    font-size: 36px !important;
}

.fileUpload {
    position: relative;
    overflow: hidden;
    margin: 10px;
}

.fileUpload input.upload {
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity=0);
}
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>


<div class="fileUpload btn btn-primary btn-lg">
        <span>Foto aufnehmen</span>
        <input type="file" accept="image/*" name="sampleFile" id="cameraImg" class="upload" onchange="processImg(this)"
               value="">
    </div>
Answer:1

You got a bunch of answers to your problem quickly, but I think it is also important to show you how we found out what the problem is in such a short time, that is, how to debug such problems generally.

If you inspect the element(s) in your developer console and hover over it in the code, you can see the outlines highlighted.

enter image description here

That way, you can see that the input element itself is not as high as the button and that's why any click outside of that area didn't trigger the input's click event.

From that point on, you could have come up with your own solution (setting height: 100% as some answers suggested, or also top: 0; right: 0; bottom: 0; left: 0, etc.).

Answer:2

You can fix this by setting height: 100% on the input:

.btn-lg {
  font-size: 36px !important;
}
.fileUpload {
  position: relative;
  overflow: hidden;
  margin: 10px;
}
.fileUpload input.upload {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0;
  padding: 0;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  filter: alpha(opacity=0);
  border: 1px solid #C00;
  height: 100%; /* add this rule */
}
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<div class="fileUpload btn btn-primary btn-lg">
  <span>Foto aufnehmen</span>
  <input type="file" accept="image/*" name="sampleFile" id="cameraImg" class="upload" onchange="processImg(this)" value="">
</div>
Answer:3

Set width:100%; height:100%; for input.upload it works... check below snippet

.btn-lg{
    font-size: 36px !important;
}

.fileUpload {
    position: relative;
    overflow: hidden;
    margin: 10px;
}

.fileUpload input.upload {
  width:100%;
  height:100%;
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity=0);
}
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>


<div class="fileUpload btn btn-primary btn-lg">
        <span>Foto aufnehmen</span>
        <input type="file" accept="image/*" name="sampleFile" id="cameraImg" class="upload" onchange="processImg(this)"
               value="">
    </div>
Answer:4

GoogleMaps is shown as gray box instead of map. And on windows resize it works correctly. On window load maps show like this: After window resize map works correctly: <div style="width:100%; ...

GoogleMaps is shown as gray box instead of map. And on windows resize it works correctly. On window load maps show like this: After window resize map works correctly: <div style="width:100%; ...

  1. google maps shows cops
  2. google maps shows wrong location
  3. google maps shows directions instead of map
  4. google maps shows offline
  5. google maps shows my location wrong
  6. google maps shows old location
  7. google maps shows for development purposes only
  8. google maps shows wrong currency
  9. google maps shows wrong time
  10. google maps shows black screen
  11. google maps shows dead body
  12. google maps shows submerged car
  13. google maps shows up black
  14. google maps shows police
  15. google maps shows wrong location for address
  16. google maps shows wrong currency iphone
  17. google maps shows preview not start
  18. google maps shows wrong city
  19. google maps shows no visited places
  20. google maps shows euros instead of dollars

Im just curious to know the best practice for either toggling a class or just adding and removing it during a mouseenter/mouseleave state using jquery. Both seem to work fine im just not to sure which ...

Im just curious to know the best practice for either toggling a class or just adding and removing it during a mouseenter/mouseleave state using jquery. Both seem to work fine im just not to sure which ...

  1. jquery add/remove class
  2. jquery add/remove attribute
  3. jquery add/remove input fields dynamically
  4. jquery add/remove class on scrolltop
  5. jquery add remove class
  6. jquery add remove class onclick
  7. jquery add remove attribute
  8. jquery add remove class onclick codepen
  9. jquery add remove style
  10. jquery add remove disabled attribute
  11. jquery add remove css class
  12. jquery add remove css
  13. jquery add remove required attribute
  14. jquery add remove
  15. jquery add remove element
  16. jquery add remove id
  17. jquery add remove class toggle
  18. jquery add remove event listener
  19. jquery add remove element dynamically
  20. jquery add remove select options

I want to make my website faster by changing the content code via Ajax instead of navigating and reloading the page. But I also care about non-Javascript users so I want to use normal links instead of ...

I want to make my website faster by changing the content code via Ajax instead of navigating and reloading the page. But I also care about non-Javascript users so I want to use normal links instead of ...

In Leaflet choropleth to assign colors you can use this function. http://leafletjs.com/examples/choropleth.html function getColor(d) { return d > 1000 ? '#800026' : d > 500 ? '#BD0026' ...

In Leaflet choropleth to assign colors you can use this function. http://leafletjs.com/examples/choropleth.html function getColor(d) { return d > 1000 ? '#800026' : d > 500 ? '#BD0026' ...