0

Is it correct to call a regular JavaScript function in a jQuery script or should it be external (it will only be access/used by the jQuery script)? I know that it works but I want to make sure that I am using best practice. For example:

$(function(){

    $('.click1').click(function(){
         dofunction();
    }

    $('.click2').click(function(){
         dofunction();
    }

    function testing(grid_array){
         alert('function works!');  
    }

});
2
  • 4
    jQuery is JavaScript. Is it ok to have a JavaScript function inside a JavaScript function? Yes! Commented Mar 24, 2013 at 14:53
  • You're creating a closure. Commented Mar 24, 2013 at 15:47

1 Answer 1

3

jQuery is a JavaScript library adding facilities, most of them helping to deal with the DOM, AJAX, or crossbrowser issues. Your jQuery script is thus also a JavaScript one.

It's perfectly normal, recommended and fine to call non jQuery based functions from code made using jQuery. In fact, you could hardly avoid that.

Related: What is the difference between jQuery and JavaScript

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

2 Comments

I love it when you're pretentious and answer as community wiki because your 'moral code' stops you from "accepting the rep" :P
@user2056238 jQuery is a library built in javascript. You're asking if it's ok calling a function from another function in JavaScript? Then yes, it is.

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.