what is wrong with this jquery delegate code?
function onBodyLoad()
{
document.addEventListener("deviceready",onDeviceReady,false);
//for testing in safari only, comment out for deploy to iphone with phonegap
$(document).ready(function(){
loadPage('mainmenu', 'Home');
$('#m开发者_如何学JAVAenus').toggle();
//I have a nested div in this index.html file with id=menubottbutt
$("div").delegate("#menubottbutt","click",toggleMenu());
$("div").delegate(".menuitem","click",toggleMenu());
});
}
In the body element I have this
When this runs and I hit the delegate line I get the error ** TypeError: 'undefined' is not a function (evaluating'$("div").delegate("#menubottbutt","click",toggleMenu())')
And of course I have the method toggleMenu defined above and it works when called from elsewhere. It looks like this `function toggleMenu() {
$('#menus').toggle('slow');
$('#menubottbutt').toggleClass('pressed');
} `
Thanks
PS this is what i have so far: in my onBodyLoad I will use $("#menubottbutt").click(function(){toggleMenu();}); and elsewhere at opportune places I will call: $(".menuitem").click(function(){toggleMenu();}); this seems to address my issues but it would probably be better if i could get delegate to work.
sorry but I didn't get your problem.
while reading your code I guess that there are 3 divs on your page that should execute a specified method when a user clicks on one off them.
So my solution would be in html
<div id="menu" class="menu"></div>
<div id="2ndMenu" class="menu"></div>
<div id="3rdMenu" class="menu"></div>
the JS would look like this
$(document).ready(function(){
$('.menu').click(function(){toggleMenu()});
});
Hope that's what you're lookin for
Thorsten
try
$("div").delegate("#menubottbutt","click",function(){toggleMenu();});
$("div").delegate(".menuitem","click",function(){toggleMenu();});
third parameter has to be function name
either is good
- "toogleMenu()"
- "toggleMenu"
- function(){toggleMenu();} // this one is recommended
精彩评论