Learn jQuery

jQuery width()

jQuery width() method is used to sets or gets the height of the matched elements.

When we used jQuery css() method to return width, This method returns the width of the FIRST matched element.

When we used jQuery css() method to set width, This method sets the width of ALL matched elements.

Syntax

jQuery.(selector).width() // Return the width for the matched elements jQuery.(selector).width(value); // Set the width for the matched elements

Example

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery width() Example </title>
</head>
<div>Hello, I am div. </div>
<input type="button" value="Press Me" id="pressMe">
<div></div>
</html>
Javascript
$(document).ready(function(){
$("#pressMe").click(function () {
alert($("div").width());
});
});