jQuery > Manipulations methods

.width() - Get & set width of element in jQuery

How to get and set the width of an element in jQuery?

To get and set the width of an html element, width() method can be used. If we pass parameter, it sets the width of the element otherwise it simply gives the width of the element.

      $("h1").css("background", "#c0c0c0").width("200px");

Above code snippet will first change the background color and set the width of the “h1” tag to 200px.


Above code snippet will show the width of “h1” element in JavaScript alert.

 Views: 4753 | Post Order: 52

Write for us

Hosting Recommendations