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 7784275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:04:09+00:00 2026-06-01T20:04:09+00:00

This (jQuery) function is invoked on jQuery(document).ready and jQuery(document).resize . It runs fine on

  • 0

This (jQuery) function is invoked on jQuery(document).ready and jQuery(document).resize. It runs fine on the ready condition but on resize the events go a bit screwy. They either inherit functionality or in the case of the slideToggle seemingly fire for each resize.

(function(jQuery){
    jQuery.fn.responsive = function() {
        // Vars
        var menuButton = jQuery('nav #menu-button');
        var menuItems = jQuery('nav ul');
        var menuLinks = jQuery('nav ul li a.scroll');
        var viewportW = jQuery(window).width(); 
        var viewportH = jQuery(window).height();  
        // Menu links
        menuLinks.click(function(e){
            if (viewportW > 800) {
                e.preventDefault();
                e.stopPropagation();
                var pos = jQuery(this.hash).offset().top;
                jQuery('html,body').animate({scrollTop: pos}, 1000);
            } else if (viewportW < 799) {
                e.stopPropagation();
                menuItems.slideUp('fast'); // Hide menu on click
            }
        });
        // Menu button
        menuButton.click(function(e){
            menuItems.slideToggle('fast');
            //e.stopPropagation();
            //e.preventDefault();
        });
    }
})(jQuery);

What am I doing wrong? I have tried to kill event propagation but to no avail.

EDIT:

This runs after:

// Doc ready
jQuery(document).ready(function() {
    // Run functions
    jQuery().responsive();
});


// On resize
jQuery(window).resize(function(){  
    jQuery().responsive();
});
  • 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-01T20:04:10+00:00Added an answer on June 1, 2026 at 8:04 pm

    When you call one of the callback registation functions likes $(someElement).click(...), you are actually adding a handler for that event. If you call the function twice with the same, the handler gets called twice. Do demonstrate, try this html page (with jquery.js in the same page):

    <html>
    <head>
    <script src="jquery.js"></script>
    <script>
        function addhook() {
            $("div").click(function(e) {
                console.info("click!");
                $("body").append($("<div>click!</div>"));
                return false;
            });
        }
    
        $(function() {
            addhook();
            $(window).resize(addhook);
        });
    </script>
    </head>
    <body>
    <div><a href="#">Click me</a></div>
    </body>
    </html>
    

    On first loading the page, it behaves as expected, but then after resizing the window, clicking “Click me” gets more than one “click!”.

    The only reason you would have for re-registering a handler is if the respective elements have been destroyed and re-created.

    If this is happening, and it’s not convenient to attempt to reliably re-register the handlers when necessary, consider using delegated events or .live().

    Also note the .off() function which can remove all of the handlers on a set of elements.

    Lastly, you should probably change

    jQuery.fn.responsive = function() {
    

    to

    jQuery.responsive = function() {
    

    adding to jQuery.fn adds functions that can be called from jQuery objects, i.e. allowing, say,

    $("div").responsive();
    

    For some reason these functions are also added to the jQuery object itself, so it still works, but the latter makes the function’s purpose more clear and keeps the jQuery class clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery UI; Draggable http://jqueryui.com/demos/draggable invoked like this: $(document).ready(function(){ $(#side_bar).sortable({ revert: true
On document ready I run this code: jQuery(document).ready(function(){ jQuery('#button').click(function() { jQuery('#contact_form').load(/Users/mge/Downloads/jquery-ajax-1/readme.txt); return false; });
I am using this jquery function that works fine in win/mac FF 3.5 and
So I know what this does: $(document).ready(function(){ // Your code here... }); Now I
I'm using this Jquery function for available username check. How can I fire this
I've got this jQuery function: function phpmail(){ $.post('mail.php',{name:$(#name).val()}, function(out){ alert(out); }); } and this
I need to put a one second delay in this jQuery function so that
This my jquery function, function getRecordspage(curPage, pagSize) { // code here $(.pager).pagination(strarr[1], { callback:
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
Hai this is my jquery function, function getRecordspage(curPage, pagSize) { $.ajax({ type: POST, url:

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.