Load Javascript function when opening the page

Asked

Viewed 4,017 times

1

I don’t know much about it, but I’ll try to explain.
Currently when I pass the mouse over a div with class tooltips, the script below is executed:

$('.tooltips').tooltip();

However, I would like this to happen as soon as I load the page, there is no need to pass the mouse on the div or click on it.

How can I do that?

  • It may be quite likely that this function shows the tooltip after a Hover event in the element. In this case an alternative would be to fire a Trigger with the event in the element to activate the tooltip.

  • Era this what did you want to do @Rodrigosegatto ? If not, you could edit your question, enhance it and add more information?

2 answers

1

You can do it this way:

$(document).ready(function() {
    $("#link").tooltip({ show: {duration: 800} });
    $("#link").trigger('mouseenter');
});

$('html').click(function() {
    $("#link").trigger('mouseleave');
});

What this will do is show the tooltip using the option .show when the document is ready, simulating the action of mouseenter/mouse hover link and then when clicked anywhere in the document, remove this action with the mouseleave.

Here’s an online jsFiddle example: http://jsfiddle.net/nf0hhmm2/

0

Since you are using Jquery and not pure Javascript, try $(document).ready(suaFunção)

  • this: $(Document). ready(tooltip); ? It didn’t work here

  • Now that I get it. This is Jquery’s own function. Actually, it’s not meant to do what you want. An alternative would be to shoot this event in hand, but you can imagine the chaos (Hover at all at the same time??)

  • It worked like this: $('. tooltips'). tooltip('show');

  • with or without $(Document). ready()?

  • No. However, when I take the mouse from the top of the tooltips class, it disappears. What can I put to solve?

  • It disappears after you take the mouse off one of the places where they have tooltip? Well, I didn’t think it would work, but I would try to add another call to that method in the onblur (event that shoots when you take the mouse off) of those components, so.

  • Pablo, I couldn’t understand..

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.