views:

12907

answers:

1

hi, can we call jquery $(document).ready(function(){ } from normal javascript funtion .like i have a button .button on click function i have to call the jquery ready funtion.is it possible. Thanks Usman.sk

+6  A: 

If you are calling it from another javascript function, drop the $(document).ready part

function f1(){
 $('#idhere').something;
}

or if you want to call a function only when the document is ready, put the function call inside $(document).ready

$(document).ready(function(){
 function f1(){
  //do something here
 }
});

But you are not taking advantage of jquery's full functionality here. If you want to associate an onclick event with an element, you can do it like so:

<button id='button1'></button>

In the js file:

$('#button1').click(function(){
 //do the onclick sequence here
});
trex279