1

I have used a script I have found. Where it should do some thing when the mouse hovers over the element

    $this.hover(
        function () {
            tip.html("<p>" + tTitle + "</p>");
            setTip(tTop, tLeft);
            setTimer();
        },
        function () {
            stopTimer($this);
            tip.hide();
        }
    );

But i want to execute it, without I have to hover the mouse over the element?

How can I do that?

1
  • That script doesn't tell anybody anything. You'd have to show us more to get a good answer. Commented Aug 26, 2010 at 11:16

4 Answers 4

1

You can pull the code out of the function:

tip.html("<p>" + tTitle + "</p>");
setTip(tTop, tLeft);
setTimer();
Sign up to request clarification or add additional context in comments.

Comments

1

To trigger the hover on:

$this.trigger('mouseover');

To trigger the hover out:

$this.trigger('mouseout');

Another choice is to move the definition outside of the callback, and do it like this:

function onMouseOver() {
    tip.html("<p>" + tTitle + "</p>");
    setTip(tTop, tLeft);
    setTimer();
}

function onMouseOut() {
    stopTimer($this);
    tip.hide();
}

// bind the hover event

$this.hover(onMouseOver, onMouseOut);

// or use them manually:

onMouseOver();
onMouseOut();

2 Comments

.hover() maps to mouseneter and mouseleave, rather than mouseover and mouseout :)
I'm fairly sure that triggering mouseover and mouseout trigger the hover events.
1

I have tried to pull the code out of the function, but that didn't help. But the problem was that i tried to call a function that hadn't been initialized yet.

Sorry for the inconvenience, and thanks:)

Comments

0

If you want it to run outside of the hover be sure to enclose the function calls in a $(document).ready or your elements wont be ready without the DOM loaded

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.