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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:52:07+00:00 2026-05-25T02:52:07+00:00

I am working on a small project with jQuery, so far so good, but

  • 0

I am working on a small project with jQuery, so far so good, but I am having an issue with jQuery’s .live() function.

In my source code below you will see:

colourMenu.children('li').live('click', selectColour);

The list elements are populated to an empty UL element via an ajax request which parses JSON. Can anyone tell me why it wont apply the live function? If it was working it would update a hidden input field by the notion of updateOption();

NOTE: the json request is called after the selectMaterial method has been actioned

(function($) {
    $.fn.juniperNotebooks = function() {

        /*
        == Default
        */

        var ajaxFile = 'notebookAPI.php';
        var nopt = $('#notebookSelectedOpts'); 
        var complete = false;   
        var debug = true;

        /*
        == Attributes
        */  

        // Steps
        var actions = {
            size: false,
            material: false,
            colour: false,
            paper: false
        }

        // Extras
        var extras = {
            emboss: false,
            elastic: false,
            pen: false,
            pocket: false
        }

        // Buttons
        var sizeButton = $('.btn.size');
        var materialButton = $('.btn.material');
        var colourButton = $('.btn.matcolour');

        // Menu's
        var sizeMenu = $('.menu.size');
        var materialMenu = $('.menu.mats');
        var colourMenu = $('.menu.colour');

        init();

        /*
        == Plugin Functions 
        */

        function init() {

            // CSS Opacity for all but the first button
            $('.btn').css('opacity', 0.5).first().css('opacity', 1).addClass('req');

            // Attach refresh function to reset link
            $('.refresh').bind('click', resetPage);

            // Attach click to first button: Size
            sizeButton.bind('click', showSizes);

            // Attach click handlers to options:
            sizeMenu.children('li').bind('click', selectSize);
            materialMenu.children('li').bind('click', selectMaterial);
            colourMenu.children('li').live('click', selectColour);

        }

        /*
        == Plugin Functions 
        */

        /*
        == Menu Selector Functions 
        */

        function showSizes() {              
            delegateActiveButtonState(sizeButton);
            toggleMenu(sizeMenu);                           
        }

        function showMaterials() {
            delegateActiveButtonState(materialButton);
            toggleMenu(materialMenu);       
        }

        function showColours() {    
            delegateActiveButtonState(colourButton);    
            toggleMenu(colourMenu);         
        }       

        /*
        == Additional Menu Selector Functions 
        */

        function toggleMenu(menu) {

            if( menu.is(':hidden') ) {
                menu.slideToggle(500);      
            } else {
                menu.slideToggle(500);
            }       

        }

        function hideMenu(menu) {
            return menu.slideToggle(500);
        }

        /*
        == Option Selector Functions
        */      

        function selectSize() {

            var option = $(this).data('size');  
            delegateActiveButtonState(sizeButton);

            if( !checkComplete() ) {

                updateOption('selectedSize', option);   
                debug__(option+' size has been selected.');

                if( option == 'a4' ) {

                    updateOption('selectedPaper', 'lined'); 
                    debug__('Lined paper has been selected by default.');       

                } else { updateOption('selectedPaper', '');  }

                hideMenu(sizeMenu);
                sizeButton.removeClass('req');

                actions.size = true;

                materialButton.unbind('click', showMaterials).bind('click', showMaterials).css('opacity', 1).addClass('req');

            } else {

                // Do stuff after we have already made a notebook

            }           

        }

        function selectMaterial() {

            var option = $(this).data('matid'); 
            delegateActiveButtonState(materialButton);

            if( !checkComplete() ) {

                updateOption('selectedMaterial', option);   
                debug__('Material ID: '+option+' has been selected.');

                hideMenu(materialMenu);
                materialButton.removeClass('req');

                actions.material = true;

                colourButton.unbind('click', showColours).bind('click', showColours).css('opacity', 1).addClass('req');

                colourMenu.empty();
                getAvailableColours( option );

            } else {

                // Do stuff after we have already made a notebook

            }           

        }

        function selectColour() {

            var option = $(this).data('colourid');  
            delegateActiveButtonState(colourButton);

            if( !checkComplete() ) {

                updateOption('selectedColour', option); 
                debug__('Colour ID: '+option+' has been selected.');

                hideMenu(colourMenu);
                colourButton.removeClass('req');

                actions.colour = true;

                // if for paper selection here..
                //colourButton.bind('click', showMaterials).css('opacity', 1).addClass('req');

            } else {

                // Do stuff after we have already made a notebook

            }           

        }               

        /*
        == Global Functions
        */

        function getAvailableColours(materialID) {

            if( colourMenu.children('li').length == 0) {
                $.getJSON('json.php?mid='+materialID, function(data) {
                  var items = [];

                  $.each(data, function(key, val) {
                    items.push('<li data-colourid="' + key + '">' + val + '</li>');
                  });

                  colourMenu.append(items.join(''));

                });
            }           

        }

        function updateOption(opt, val) {
            return nopt.children('#'+opt).val(val);
        }

        function getOption(opt) {
            return nopt.children('#'+opt).val();
        }

        function resetPage() {
            if( confirm('Are you sure you want to reset this page? All data will be lost.') ) {
                location.reload();
            }
            return false;
        }

        function delegateActiveButtonState(btn) {

            if( !btn.hasClass('active') ) {
               return btn.addClass('active');
            } else { return btn.removeClass('active'); }    

        }

        function checkComplete() {
            if( complete ) {
                return true;
            }
        }

        function debug__(msg) {
            if(debug) {
                console.log(msg);
            }
        }

    };
})(jQuery);
  • 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-25T02:52:08+00:00Added an answer on May 25, 2026 at 2:52 am

    .live() [docs] only works directly on selectors:

    DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.

    There might be other issues with your code, but that is definitive one. Instead of posting a bunch of code and having us trying to figure out how it works, you should create a http://jsfiddle.net/ demo.

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

Sidebar

Related Questions

I'm working on a small django project that will be deployed in a servlet
I'm working on a small project in QT (well, pyQT4 actually, but it shouldn't
I'm working on a small project that displays answers for a survey. I'm having
I am working on a small project, and am having two tiny problems with
I'm working on a small project which will basically do some Facebook stuff and
I'm working on a small project, where I'm using the codeigniter php framework, but
I'm working on a small project to help me tag content on Flickr. I've
I'm working on a small project in VB.Net where I get a input from
I am working on a small project that is receiving XML data in string
I am working on a small project for learning PHP better. This project has

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.