I have several elements in the list and want to highlight the one that the user clicks, applying some css style, possibly background color, etc.
My HTML looks like this:
<ul class="thumbnails"> <li> <a href="#" class="thumbnail"> <img class="giftthumb" src='thumb1.jpg' alt=""> <span class="gifttitle">Thumb1</span> </a> </li> <li> <a href="#" class="thumbnail"> <img class="giftthumb" src='thumb2.jpg' alt=""> <span class="gifttitle">Thumb3</span> </a> </li> <li> <a href="#" class="thumbnail"> <img class="giftthumb" src='thumb3.jpg' alt=""> <span class="gifttitle">Thumb3</span> </a> </li> </ul>
jQUery to retrieve the selected item:
$('.thumbnail').click(function(e) { e.preventDefault(); ??? })
source share