Highlighting clicked image using jquery and css

Highlighting clicked image using jquery and css

Highlighting clicked image using jquery and css:


Highlighting clicked image using jQuery and Css - Javadomain.in


If you see the images in online shopping websites, they will be highlighting the product image on click of the image. It will give more interaction to the user. This can be done using jQuery and css.





Import the jQuery Plugin:

<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

CSS Source:

<style type="text/css">
/* Image display styles - Javadomain.in */
    float: left;
    margin-left: 124px;
    margin-top: 150px;

/* Image active and inactive classes  - Javadomain.in */

a img.activeImg {
    background-position: -1px 1px;
    opacity: 1;
    padding: 10px;

a img.inactiveImg {
    background-position: -1px 0;
    -moz-opacity: 0.2;
    filter: alpha(opacity=20);<a href="http://www.ngdeveloper.com/wp-content/uploads/2014/11/Highlight_Clicked_Image.zip">Highlight_Clicked_Image</a>
    padding: 10px;
    border: 1px solid black;


We used jQuery to add the “activeImg class” to the clicked image and “inactiveImg class” to the all remaining images.

here activeImg and inactiveImg are the image class names, both are having only the opacity difference in the above css styles. Here the logic is to display the images with 0.2 opacity by default and on click of the image we are making the opacity to 1.


jQuery Source:

<script type="text/javascript">
	$("img").click(function() {
	alert("You have clicked:   "+this.id);


image highlight output


jQuery Recommended Books:

940 total views, 3 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.