JqueryNo Comments

default thumbnail

Jquery dimension methods are used to set or return the width and height of the elements. Width() and height() jquery methods are used in jquery. Here is now to use practically.

HTML

<div id="box">This is a box</div>

<button>Click Here</button>

CSS

#box{
  height: 200px;
  width: 400px;
  padding: 5px;
  margin: 3px;
  border: 1px solid #444;
}

Jquery

$(document).ready(function(){
  $("button").click(function(){
    var txt = "";
    txt += "Width of box: " + $("#box").width() + "</br>";
    txt += "Height of box: " + $("#box").height();
    $("#box").html(txt);
  });
});

Using the above jquery script, you can get the height and width of the html element. Don’t forget to link the jquery min file above the jquery code. If you have any issue, comment us in the comment box.

Be the first to post a comment.

Add a comment