HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style> div{ border:1px solid black; width:100px; height:50px; margin: 10px; } </style> </head> <body> <h1>jQuery width() Method</h1> <div>Child 1</div> <div>Child 2</div> <p>Click on the button to change the first div's width to 100px and second div's width to 150px.</p> <button>Click Me</button> <script> $(document).ready(function(){ $("button").click(function(){ $("div").width(function(index, myWidth){ $("div").eq(index).width(myWidth * (index+2)); }); }); }); </script> </body> </html>
OUTPUT
×

Save as Private