0

How to use jquery functions more similar to javascript ? What i mean about that, is to call a function from script tag in html like do_something()and this will trigger the function. I have on my jquery script file $(document).ready(function() {... } and it contains some functions with onclick handlers and others, but how to trigger function by just simply inserting name of that function in html, which can be call in some instances while processing code and loading page ?

2
  • Your question is not clear, can you provide some more code, and explain in more detail? Commented Jan 26, 2014 at 22:43
  • What i want to achieve is to remove disabled attibutes from checkboxes and radio buttons when admin will go into patricular page. I know how to do it with jquery and im doing it within $(document).ready(function(){...} but i don't want to trigger this "removing attributes function" on ready, and i can't make it work somehow outside ready function. Commented Jan 27, 2014 at 11:45

2 Answers 2

1

jQuery is just a JavaScript library. Its functions are JavaScript functions. You can call them in the same way as any other JavaScript function.

Passing a function as an argument to ready just means "When the ready event fires, call this function". It's similar to setTimeout(function () { … }, 5000) only with a condition other than "after 5 seconds".

Sign up to request clarification or add additional context in comments.

Comments

0

It sounds like you are having trouble with the scope that $(document).ready(function(){...}) creates;

You will want to place do_something() outside of the $(document).ready(). This will allow your DOM (in html) handlers to call it.

Also keep in mind that $(document).ready() is only used to make sure that the DOM is ready before JS tries to interact with it. If you are placing your JS in the html, the DOM will be ready by the time the functions are called.

You may want to see this question for more details: Global javascript variable inside document.ready

1 Comment

I understand how ready works, but the problem is that if i put my code in "ready" function it shows results immediately(i have different files that are using my jquery script file and i don't what all of them to trigger certain code),and putting function definition outside "ready" don't return any results, even when im calling this function after DOM elemets suppose to be created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.