0

i am trying to use jquery selector with and array of objects. here is an example..

//Declaration
    var filterItems = Array();
    filterItems[0] = { clickDiv: "CategoryPanelHeader", div: "NarrowByCategoryPanelWrapper" };
    filterItems[1] = { clickDiv: "ExpandYourResultsHeader", div: "ExpandResultPanelWrapper" };
    filterItems[2] = { clickDiv: "Keyword", div: "KeywordDiv" };
    filterItems[3] = { clickDiv: "Manufacturer", div: "NarrowByManufacturerPanelWrapper" };
    filterItems[4] = { clickDiv: "Credentials", div: "CredentialsDiv" }; 

and the selector

$(document).ready(function () {
  //binds the click events...
  for (var i = 0; i < filterItems.length; i++) {
     $('#'+ filterItems[i].clickDiv).live('click', function () {
     togglemenu($('#' + filterItems[i].div));
     });
  }
});

i am able to read each item properly when i make an alert but jquery is not binding the click events.

how would i go about using an array to bind the onclick events?

Ishey4
  • 327
  • 3
  • 13

1 Answers1

0

i got it! you just have to call an outside function

   $(document).ready(function () {
            // gets all the click parameters...
            for (var i = 0; i < filterItems.length; i++) {
                bindClicks(($('#' + filterItems[i].clickDiv)), ($('#' + filterItems[i].div))  );
            }
        });
           function bindClicks(clickdiv, expanddiv) {
             //binds the click events
            clickdiv.click(function () {
                togglemenu(expanddiv);
            });
        }
Ishey4
  • 327
  • 3
  • 13