Malasorte Malasorte - 2 years ago 140
Javascript Question

Combine onload, onresize and onclick

The function below runs on document load and document resize:

$(window).on("resize", function () {
// code

How can I also trigger the function when the user clicks on
<div id="my_div"></div>

Answer Source

Move your function to some named function and call it on event:

function myFunction () {

$(window).on("resize", function () {

$('#my_div').click(function () {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download