w3resource

jQuery: Increase the width of a division by specified pixels once it is clicked

jQuery Fundamental - II : Exercise-66

Increase the width of a division by specified pixels once it is clicked.

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>Increase the width of a division by specified pixels once it is clicked.</title>
</head>
<body>
<div id="box">Click me to expand</div>
</body>
</html>

CSS Code:

#box {
background: red;
color: black;
width: 100px;
padding: 10px;
}

JavaScript Code :

$( "#box" ).one( "click", function() {
$( this ).css( "width", "+=150" );
});

See the Pen jquery-fundamental-exercise-66 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Change the color of any paragraph to red on mouseover event.
Next: Click a word in the paragraph and highlight it.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.