Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:30:16+00:00 2026-06-12T16:30:16+00:00

I want to bind/unbind event listener to window resize I am using the .on()

  • 0

I want to bind/unbind event listener to window resize I am using the .on()/.off() functions to do it, because .off() require to pass the same function as in .on() I created a separate function which is passed in both places.

Here is the code (not working):

var i = 0;
function onResizeListener(){
    $('#debug').html(i);
    i++;
}
$(document).ready(function() {
    $(window).on('resize',onResizeListener());
});

Example: http://jsfiddle.net/eRupC/2/

This one is working: http://jsfiddle.net/eRupC/1/ when I wrap the onResizeListener() with an anonymous function.

The desirable result in the example: When you resize your window the number has been changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:30:17+00:00Added an answer on June 12, 2026 at 4:30 pm

    Try this if you need to pass something to onResizeListener. If not, remove the parenthesis from onResizeListener as the the other answers say. Bind Documentation

    $(document).ready(function() {
      var x = 2;
      var y = 4;
      $(window).bind('resize', function() {
        onResizeListener(x, y);
      });
    });
    

    This would also work:

    $(document).ready(function() {
      $(window).on('resize', function() {
        onResizeListener();
      });
    });
    

    To unbind the function call from the resize event but still pass parameters to the function you could use:

    $(document).ready(function() {
        //bind
        $(window).bind('resize', { foo: 'bar' },onResizeListener);
    
        //unbind, wrap in event you wish to use to unbind it
        $(window).unbind('click', onResizeListener);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to bind a function to an event but I want to change
I want to bind a click event with the element: $('a').click(function(){ btn_submit_pressed=false; }); Now,
I have removed click event by using $('#div_id').unbind('click'); but after some condition I want
I have a function SomeFunction(event) - I want to bind a 'tap' event to
There are my codes: Jquery $(function() { $(#evtTarget).bind(mouseover,highlighted); $(#evtTarget).bind(mouseleave,highlighted); $(#evtTarget).bind(click,function(){ $(#evtTarget).unbind(mouseover,highlighted); $(#evtTarget).unbind(mouseleave,highlighted); $(#evtTarget).html(Off.Click for
I have this jQuery code; $(function () { $(window).unbind(beforeunload); $(window).bind(beforeunload, function () { return
I want to bind an event to a certain class and ID for when
Code : $(document).ready(function(){ $(#main_div).bind('click', function(e){ var x = event.pageX-document.getElementById(main_div).offsetLeft; var y = event.pageY-document.getElementById(main_div).offsetTop; if(...)
with the following three lines: $( .thumb ).bind( mousedown, function() { $('.thumb').not(this).unbind('mouseenter mouseleave'); });
I want to bind an element with a function via live() method. The function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.