Function Calling order issue with JQuery
Hi,
I'm beginner in JQuery, trying to develop a plugin/control working like this http://jsfiddle.net/jddevight/esS4k/. I am populating drop down list with an external Json file. Please see the code below before reading my problem in next line.
Issue: Issue is if i try to add multiple <div> in html page, i must have to follow the function caling order in selecttree.js file. See below please, if i define <div> in the order bellow.
- <div id="ahmadcontrol"></div>
- <div id="customformcontrol"></div>
I have to call function in select tree in reverse order as it shows in red text in selectree.js file. If i call in random order, except first, rest of the controls do not work properly. What could be the reason? I appreciate if someone reply with solution. Thanks
<body>
<div id="ahmadcontrol"></div>
<div id="customformcontrol"></div>
</body>
- selectree.js
- $.getScript('js/slctBxStub.js',function(){
- slctbxstub('data/selectTree/example.json','customformcontrol');
- });
- $.getScript('js/slctBxStub.js',function(){
- slctbxstub('data/selectTree/example.json','ahmadcontrol');
- });
- slctBxStub.js
- function slctbxstub(jsonfile,divid){
- var divelementabc=divid+"1";
- document.getElementById(divid).innerHTML='<form id="form1">'+
- '<input type="text" class="inbx1" id='+divelementabc+' name="s" value="" />'+
- '<input type="Button" id="buttonval" value="" class="icon4 ui-widget-content ui-corner-all"/> '+
- '</form>'+
- '<div id="tree1" class="tree">'+
- '</div>';
- $('#selectProperty').on('click', function(){
- $('#tree1').removeClass('hide').addClass('show');
- });
-
- var tree = $('#tree1');
- tree.tree({
- dataUrl : jsonfile,
- dataFilter: function(data) {
- return data['properties'];
- },
- autoOpen: false,
- dragAndDrop: true,
- selectable: true,
- onCreateLi: function(node, $li) {
- // Add 'icon' span before title
- console.log(node);
- var element = $li.find('.jqtree-title');
- console.log(element);
- element.append('<span class="createicon"></span>');
-
- }
- });
- //tree.bind('tree.select', function(event){
- // $('#'+divelementabc+'.inbx1' ).remove();
- $('#'+divid+'.inbx').remove();
- // $('#'+divelementabc).//remove form element
- // $('#'+divelementabc).append('<input type="text" size="25" id="inbx" value="'+event.node.name+'"/>');
-
- //});
- tree.bind('tree.select', function(event){
- console.log(event.node);
- $('#'+divelementabc).val(event.node.name);
- });
-
-
- $('#'+divid).on('click', function(event){
- tree.fadeIn('medium');
- });
-
- tree.on('mouseleave', function(){
- tree.fadeOut('medium');
- });
- tree.css('display','none');
- // get the field position
- var inputField = $('#searchwrapper');
- var fieldDiv = $('#tree1');
- var sf_pos = inputField.offset();
- var sf_top = sf_pos.top;
- var sf_left = sf_pos.left;
- // get the input field size
- var sf_height = inputField.height();
- var sf_width = inputField.outerWidth();
- fieldDiv.css("position","absolute");
- fieldDiv.css("left", sf_left);
- fieldDiv.css("top", sf_top + sf_height + 10);
- fieldDiv.css("width", sf_width);
-
- }