Call jQuery from Javascript function

Have you ever come accross a situation where you need to call Jquery from or within a Javascript function? Well, it's not that tough either. You can directly write your jQuery code within a JavaScript function. See below code.

I have placed a button on my page which makes a call to a Javascript function "Test()".
<asp:Button ID="btnName" runat="server" Text="Change CSS" 
OnClientClick="return Test();" />
Here is Javascript.
<script type="text/javascript" language="javascript">  
function Test()
        return false;
In the function Test, we can directly write "$("#btnName").css("color","red");", Instead of putting this in document.ready function. It will work in case of a small page but when the page is heavy and it's not completely loaded and you click on button, then it's quite possible that you can get an error of undefined object.

It's a best practice to always put your jQuery code in $(document).ready() function as this gives the assurance that DOM is fully loaded.

Feel free to contact me for any help related to jQuery, I will gladly help you.

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..