how to declare a global function in jquery, how do I call it from a page loaded in some div on this page using jquery load () function.
the function is simple in the 1st page
+ ----------------------------------------------- +
| main links |
+ ----------------------------------------------- |
| + ------------------------------------------- + |
| | 1st sub page ( myfun function is here) | |
| + ------------------------------------------- + |
| | + --------------------------------------- + | |
| | | | | |
| | | | | |
| | | | | |
| | | mybutton clicked myfun called | | |
| | | | | |
| | + --------------------------------------- + | |
| + ------------------------------------------- + |
+ ----------------------------------------------- +
But when I click, nothing happens ... here both functions
myfun
myfun(tab_index, acc_id){ alert(tab_index +" | +" acc_id); }
Mybutton
$("#mybutton").click(function(){ var $bottomLineBtn = $(this); $bottomLineBtn.parent().myfun('2','43234'); })
Can someone please help me .. it's too hard to find a solution .. I searched 3 hours ...
============================================= ====== ==================================
updated
here is a detailed script
- I am working on some dynamic materials using jquery
- the first page contains 2 divs, those
id=menu
and the other id=subpage1
, - I click on one link from #menu, the page loads in
#subpage1
. - page with 2 divs
#menu2
and #subpage2
- here I created a script that automatically loads pages in
#subpage2
, taking only 1 parameter .... which is the listmenu identifier. this script is ..
$ ("# menu2 li"). click (function () {
$ ("# subpage2"). load ($ (this) .attr ('page_link'));
}
}). filter ('# menu2 li: eq (0)'). click ();
on the loaded page. at the bottom, I use 2 buttons, one button works fine, it calls the function above and changes the value li: eq (1) .. that I did it.
$ ("# bottom_bar #backbtn"). click (function () {
var $ bottomLineBtn = $ (this);
$ bottomLineBtn.parent (). parent (). parent (). find ('# menu2 li: eq (1)'). click ();
})
... but the other button does not work. I want to call a function that belongs to some #subpage1
in #subpage1
. but cannot access them. I put only the function next to the above function $("#menu2 li").click(function(){
.
myfun(tab_index, acc_id){ alert(tab_index +" | +" acc_id); }
but I donβt know how to call this function from the second button loaded in #subpage2
does this script make a scene .. try to understand me .. i'm not very good at describing ...