Search code examples
javascripthtmlimagewidthborder

Adjust border width of image using javascript


var images = document.getElementById("facilityThumbNail").getElementsByTagName("img");

for (var i = 0; i < images.length; i++) {
  images[i].onmouseover = function() {
    this.style.cursor = 'hand';
    this.style.borderColor = 'red';
    // this.style.border ? ? ? ? ?
  }
}
<div id="facilityThumbNail">
  <img src="https://unsplash.it/300/300" />
</div>

Just wondering if someone can please tell me how I can adjust the width of border for this image by advising what the attribute is? It's not width...


Solution

  • Do specify the borderStyle and borderWidth

    var images = document.getElementById("facilityThumbNail").getElementsByTagName("img");
    
    for (var i = 0; i < images.length; i++) {
      images[i].onmouseover = function() {
        this.style.cursor = 'hand';
        this.style.borderWidth = '10px';
        this.style.borderStyle = 'solid';
        this.style.borderColor = 'red';
      }
    }
    <div id="facilityThumbNail">
      <img src="https://unsplash.it/300/300" />
    </div>