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 ?

norbidrak
  • 463
  • 6
  • 22
  • Your question is not clear, can you provide some more code, and explain in more detail? – elclanrs Jan 26 '14 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. – norbidrak Jan 27 '14 at 11:45

2 Answers2

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".

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
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

Community
  • 1
  • 1
wharding28
  • 1,271
  • 11
  • 13
  • 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. – norbidrak Jan 27 '14 at 12:13