- 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 height equal to the dynamic width (CSS fluid layout) in JavaScript?
To set height equal to the dynamic width in JavaScript, you can try to run the following code −
Example
<!DOCTYPE html> <html> <head> <style> .wrap { width:400px; height:300px; border:2px solid yellow; } .myChild{ width: 80%; border:1px solid red; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> var res = $('.myChild').width(); $('.myChild').css({ 'height': res + 'px' }); </script> </head> <body> <div class = "wrap"> <div class = "myChild"></div> </div> </body> </html>
Advertisements