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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:11:27+00:00 2026-05-28T08:11:27+00:00

I have inherited a jquery component that simulates a dropdown for users to choose

  • 0

I have inherited a jquery component that simulates a dropdown for users to choose an option from.

The component can be seen at http://jsfiddle.net/Qg9f4/2/ and it seems to work fine.

However, we are trying to namespace all of our scripts into a single file. In general, this works fine as per this thread. However, this component stops working when we use the same technique for namespacing. The init script seems to parse fine on $(document).ready, but nothing actually happens when the component is clicked.

I have commented in the jsfiddle as to what does and does not work.

This works

$(document).ready(function () {

    $(".dselector dt a").click(function () {
        $(".dselector dd ul").toggle();
    });

    $(".dselector dd ul li a").click(function () {
        $(".dselector dd ul").hide();
    });

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dselector")) $(".dselector dd ul").hide();
    });
});

This doesnt work

$(document).ready(zxcf.init());

var zxcf = {
    init: function() {
        $(".dselector dt a").click(function () {
            $(".dselector dd ul").toggle();
        });

        $(".dselector dd ul li a").click(function () {
            $(".dselector dd ul").hide();
        });

        $(document).bind('click', function (e) {
            var $clicked = $(e.target);
            if (!$clicked.parents().hasClass("dselector")) $(".dselector dd ul").hide();
        });
    }
};
  • 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-05-28T08:11:28+00:00Added an answer on May 28, 2026 at 8:11 am

    You’re using the zxcf variable before you’ve initialized it.

    This means that the ready() handler will be invoked right away, and so the zxcf is not yet intialized.

    http://jsfiddle.net/UtSmC/

    var zxcf = {
        init: function() {
            $(".dselector dt a").click(function () {
                $(".dselector dd ul").toggle();
            });
    
            $(".dselector dd ul li a").click(function () {
                $(".dselector dd ul").hide();
            });
    
            $(document).bind('click', function (e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass("dselector")) $(".dselector dd ul").hide();
            });
        }
    };
    
    $(document).ready(zxcf.init); // <-- pass it instead of invoking it
    

    http://jsfiddle.net/UtSmC/

    Also, you’re invoking the function instead of passing it to .ready().

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

Sidebar

Related Questions

I have just built a custom autocomplete component using jquery. My problem is that
I have inherited a VB6/Access application that we have developed and sold for many
I have inherited a poorly written web application that seems to have errors when
I have inherited a project that uses LLBLGen Pro for the DB layer. The
I have inherited a c# class 'Button' (which I can't change) which clashes with
I have a tabbed page I inherited that works through a number of queries
I have a PHP script that's being called through jQuery AJAX. I want the
I am working on a web page that is using jQuery. I have an
I inherited a project from another developer who used jQuery UI. I've added a
I have a php / mysql / jquery web app that makes 13 ajax

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.