Monday, January 26, 2009

[jQuery] Re: this (class) + id + text

Lets assume you have the following html:

<a href="#image_1" class="show_image">Show Image</a>
<a href="#otherImg" class="show_image">Show Image</a>
<a href="#image_2" class="show_image">Show Image</a>

<img src="a.png" id="image_1" alt="Some Image"/>
<img src="b.png" id="otherImg" alt="Some Image"/>
<img src="c.png" id="image_2" alt="Some Image"/>

Then the code you want is:

$('.show_img').hover(
function(){
$(this.href).show()
},
function(){
$(this.href).hide()
}
);

this.href contains the jQuery selector you want to make visible, and
corresponds with the id attribute of the images.

On Jan 26, 10:23 am, Crazy-Achmet <crazyach...@gmail.com> wrote:
> Hey,
>
> sorry for the weird topic but i couldn't find a better one so i choose
> this! ;)
>
> Right now, i got this code:
>
>                 $('.show_image').hover(
>                         function(){
>                                 $('.image').show();
>                         },
>                         function(){
>                                 $('.image').hide();
>                         }
>                 );
>
> The href looks like this:
>
> <a href="#" class='show_image' id="image_1">Show Image 1</a>
> ...
>
> So, if i mouseover one of my 10 show_image classes, all image are
> shown. What i want is, that only the image with the select ID is
> shown.
> I thought, that i could do something like this:
>
> $(this).ID of this.some text to reach the image.show()
>
> I hope you understand what i mean.
>
> Thanks for your help
>
> Flo

No comments: