jQuery innerWidth() Method
The innerWidth is an inbuilt method in jQuery that is used to return the width of the first matched element.
Syntax:
$(selector).innerWidth()
Here selector is the selected element.
Parameters: It does not accept any parameters.
Return value: It returns the width of the selector.
jQuery code to show the working of innerWidth() method:
Example: Here is an example of the above-explained method.
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
//jQuery code to demonstrate innerWidth function
// document ready
$(document).ready(function () {
// on clicking the paragraph
$("p").click(function () {
// innerWidth
document.getElementById("demo").innerHTML =
"innerWidth = " + $("div").innerWidth();
});
});
</script>
</head>
<body>
<h2 style="color: green;">
GeeksforGeeks
</h2>
<div style="height: 100px;width: 200px;
background-color: blue">
</div>
<p>
Click here to know innerWidth
</p>
<p id="demo"></p>
</body>
</html>
Output: