- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set width and height of an element using jQuery?
To set the width and height of an element using jQuery, use the width() and height() in jQuery.
Width of an element
Example
You can try to run the following code to learn how to set the width of an element in jQuery:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#button1").click(function(){ $("div").width(300); }); $("#button2").click(function(){ $("div").width(400); }); }); </script> </head> <body> <div style="height:150px;width:200px;border:2px solid gray;background-color:lightblue;"></div><br> <button id="button1">Width of div: 300</button> <button id="button2">Width of div: 400</button><br> </body> </html>
Height of an element
Example
You can try to run the following code to learn how to set the height of an element in jQuery:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#button1").click(function(){ $("div").height(250); }); $("#button2").click(function(){ $("div").height(350); }); }); </script> </head> <body> <div style="height:150px;width:400px;border:2px solid gray;background-color:lightblue;"></div><br> <button id="button1">Height of div: 250</button> <button id="button2">Height of div: 350</button><br> </body> </html>
Advertisements
To Continue Learning Please Login
Login with Google