Nick LaMarca
Nick LaMarca

Reputation: 8188

Trouble with the onmouseover function

I am having trouble getting the onmouseover function working in jquery. What I want to do is when you hover over the word "here" the image pops up. The plugin is working fine just don't know how to handle the onmouseover or hover event?

HOVER ISNT WORKING IN MY CODE

('a.lightbox').hover(function(){
  $('a.lightbox').lightBox();     
});

 <body>
    <form id="form1" runat="server">
    <div id="outer">
    <a href="image1.jpg" class="lightbox">here</a>
    </div>
    </form>
</body>

This doesnt work either.....

 $('a.lightbox').hover(function() {
    $(this).lightBox();
    });

Isn't there something where I can simply hover over a word and an image pops up?

Upvotes: 0

Views: 320

Answers (5)

grant
grant

Reputation: 745

You forgot the $. Try this

$('a.lightbox').hover(function(){
  $('a.lightbox').lightBox();     
});

Also, you can use $(this).lightBox(); instead for the second line.

Here's an example: http://api.jquery.com/hover/#hover2

Upvotes: 0

Mahesh
Mahesh

Reputation: 2256

Hey you missed the '$' sign of jQuery

see for demo http://jsfiddle.net/Vjhz3/7/

Upvotes: 1

Jacob
Jacob

Reputation: 78900

In addition to the issue @mahesh found, you should also not use the hover function; when using hover with one function, your function is used when the mouse both enters and leaves the element. Use the mouseenter or mouseover events instead.

Upvotes: 0

clumsyfingers
clumsyfingers

Reputation: 520

In addition to missing the $ sign, this code will not work because it will open all elements with the selector a.lightbox, not just the one hovered on, try this:

$('a.lightbox').hover(function(){
  $(this).lightBox();     
});

Upvotes: 0

andypaxo
andypaxo

Reputation: 6641

Two things here...

  1. You want to use $('a.lightbox') on the first line, not ('a.lightbox')
  2. I don't think that's the right way to use lightbox, have a look at the docs

Upvotes: 1

Related Questions