I have registered a trigger on window resize. I want to know how I can trigger the event to be called. For example, when hide a div, I want my trigger function to be called.
I found window.resizeTo()
can trigger the function, but is there any other solution?
Where possible, I prefer to call the function rather than dispatch an event. This works well if you have control over the code you want to run, but see below for cases where you don't own the code.
In this example, you can call the
doALoadOfStuff
function without dispatching an event.In your modern browsers, you can trigger the event using:
This doesn't work in Internet Explorer, where you'll have to do the longhand:
jQuery has the
trigger
method, which works like this:And has the caveat:
You can also simulate events on a specific element...