jQuery Get & Set Width of an Element

jQuery Set & Get width and height Of Html Elements

jQuery set and get width and height of HTML elements; In this tutorial, you will learn how to dynamically set/change or get the width and height of selected html elements like div, span, p, button, tag etc.

How to dynamically set and get the height and width of HTML element

Use jQuery width() and height() method to change/set and get html elements ( div, span, p, button, tag ) width and height.

jQuery Width() method

jQuery offers various method to manipulating html elements. The jQuery width() methods get or set the width of the selected html elements.

Syntax width() Method

Using the above syntax Get width of elements

You can use this jquery width() syntax for Set the width of elements.

Example for jQuery Width() method

This example will demostrate, you how to set or get the width of selected HTML elements using the jQuery width () method.

     #div_box_body    
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius quam at, luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante. Vestibulum id metus ac nisl bibendum scelerisque non non purus. Suspendisse varius nibh non aliquet sagittis. In tincidunt orci sit amet elementum vestibulum. Vivamus fermentum in arcu in aliquam. Quisque aliquam porta odio in fringilla non purus nisld Dapibus nec turpis vel, semper malesuada ant.

Sample paragraph to test width

Пример: Задать при клике по элементам div различную ширину.

     div < width: 70px; height: 50px; float:left; margin: 5px; background: red; cursor: pointer; >.mod   
d
d
d
d
d

Источник

Читайте также:  Float в python что это
Оцените статью