简体   繁体   中英

Call functions on events outside document.ready function in jquery

I have this doubt. I remember earlier I used to define functions for events outside document.ready function in jquery. Like

$(function(){
// some function calls
});


$("#some-id").click(function(){
// instructions
})

And this used to work, but today I tried the same. I wanted to trigger a click on a button when some other button was clicked. It didn't seem to work. Although, I tried to alert outside document.ready and it worked just fine.

I understand the use of document.ready but my click function should have worked right?

Oh, sorry! I feel stupid! I was making changes to an existing code, written by someone else. He has js included in the head. It is obvious for that to not work as the element is not included when my function is read!

Thanks guys!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM