running a function when another is clicked using jquery
When i run this $btns.first().click();
in the first function it doesnt action it where as if i click it (as per second function it works perfectly. The result is the slides all show when i click on a tab instead of just one. And then w开发者_如何学JAVAhen i click one of the inner buttons the slides all disapear leaving just one. Which is correct.
http://jsfiddle.net/p259x/
I know this is hard to understand so hopefully the link helps.
When you define the $tabs.click()
function, $btns
doesn't actually exist, so it's probably trying to click an undefined
reference. Just put the $tabs.click()
function declaration below the instantiation of $btns
.
Also, when you click on a $tabs
it doesn't update the screen correctly. The return
call in a function means that it leaves the function at that point. It will NOT continue through and run any other lines of code that exist after it. So, in your $tabs.click()
declaration, you should move the last line ($btns.first().click()
) above your return false;
statement.
Finally, you might want to move the $tabs.first().click()
and $btns.first().click()
lines, as they rely on the events being declared, and might not give you the results you want if they exist before the event declaration.
精彩评论