I have a problem in dealing with my problem. My problem is I am creating a static navigation. That uses trigger event. Because I am displaying a simple collapsible div. What I did is I include all my id name in an array and I loop it to create an event. But when I click a link i doesn't call my jquery event. Is there a way how can I prevent hard coded of navigation?
Here's my sample code:
var toggleState = true;
var header_name = ["ParentA", "ParentB", "ParentC", "ParentD"];
var child_name = ["ChildA", "ChildB", "ChildC", "ChildD"];
for (var x = 0; x < header_name.length; x++) {
$("#" + header_name[x]).click(function (e) {
if (toggleState) {
$("#" + child_name[x]).show("slide");
} else {
$("#" + child_name[x]).hide("slide");
}
toggleState = !toggleState;
});
}
<div id="ParentA">Click A</div>
<div id="ChildA" style="display: none">Child A</div>
<div id="ParentB">Click A</div>
<div id="ChildB" style="display: none">Child B</div>
<div id="ParentC">Click A</div>
<div id="ChildC" style="display: none">Child C</div>
Here's the fiddle: http://jsfiddle.net/rochellecanale/cveze/3/