jQuery: Find the total width of an element
jQuery Practical exercise Part - I : Exercise-47
Find the total width of an element (including width, padding, and border) in jQuery.
Sample Solution:
HTML Code :
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Find total width of an element (including width, padding and border) in jQuery.</title>
</head>
<body>
<p id="myText">jQuery Exercises, Practice, Solution</p>
</body>
</html>
CSS Code:
p {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
JavaScript Code:
console.log("Width + padding + borders : " + $("#myText").outerWidth());
See the Pen jquery-practical-exercise-47 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Remove disabled attribute using jQuery.
Next: Change options of select using jQuery.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/jquery-exercises/part1/jquery-practical-exercise-47.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics