views:

126

answers:

1

I have 4 links that are being displayed as an image. The a tag is displayed in CSS by a small image and the a:hover is represented by a larger image. I am using ajax to load the content that each of these links represent.

http://www.avant-gardesalon.net/site/quality-products_copy.php

How do change the CSS so that when the content (for the related link) is displayed, the image displayed is the larger image? Also, once the user clicks on another link, how do I change the previous link back to the smaller image?

+3  A: 

That means, pure css a:hover setting is not the answer, coz when mouse move out or click other places, the link will back to its normal state.

You need to handle the click event on that a, for example (suppose all a have the class product, and put the wine name as the id of the div):

$("a.product").click(function(e)
{
    e.preventDefault(); // So that the link is only handled by the following code without default action
    $("a.product").removeClass("active"); // Remove all other "active" products, ie, back into smaller image size

    var name = $(this).parent.attr("id");
    $(this).addClass("active"); // set the selected item to be "active" or larger image size in your case
    // ajax logics here...
});

and the html can be

<div id="wineName1"><a class="product">...</a></div>
<div id="wineName1"><a class="product">...</a></div>
<div id="wineName1"><a class="product">...</a></div>

so that in your css

#wineName1 {...}
#wineName1 active { // you can then target the larger image like this here }

One last bit, which is not really related to your question, is that semantically your wines could better use unordered-list (ul) to represent.

xandy
xandy - first, thanks so much for taking the time to answer! I've setup a copy so that I don't screw something up: avant-gardesalon.net/site/quality-products_copy.php/… I changed it back to a ul tag and implemented the html/css details above. I'm using onmousedown event on the a tag to call the content. I understand the js you listed above removes the "active" class (id?) and adds it to the appropriate product...but how/where do I implement the code? this is such an amazing resource, i wish my mind worked in code!
Scott
first, in your link I can't load the stylesheet. Anyway, you don't need the onmousedown in the a, so remove that one. The above code is to bind the click event to the a, which in most cases, we put that within the $.(function()) // which denotes the document ready. To further understand that, please take a look at http://docs.jquery.com/Events/ready#fn
xandy
my bad! I thought you are coding in jquery! for the code above you need to include jquery library as well which available at http://www.jquery.com
xandy
nope, not your fault. i originally stated that i was using jquery (i edited my post when i learned otherwise)..you've given me the head start that i need! thank you!
Scott