0

hello i need to call a javascript function into jquery and the function is from another file .. i don't know how to do it :/ this is in the jquery file

if ( slotNumber == cardNumber ) {
    ui.draggable.addClass( 'correct' );
    ui.draggable.draggable( 'disable' );
    $(this).droppable( 'disable' );
    ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' }  );
    ui.draggable.draggable( 'option', 'revert', false );
    correctCards++;
    count ++;
    //i want to add the function here
} 

here's the js.js file

<script type = "text/javascript">
    function fun() {
        document.write("it's working");
    }
</script>

anyone have any idea how to do it ?

3
  • If need to include both files (using script tags or jQuery getScript) and then just call the function fun() in second file. Commented Feb 23, 2016 at 14:33
  • 2
    external .js files should NOT have <script> tags. it should be just the bare js code. and you load those files via <script src="file.js"></script> Commented Feb 23, 2016 at 14:35
  • You should not have script tags in js file script tags go to html file if you wan to include the file or create inline script like your second snippet. Commented Feb 23, 2016 at 14:35

2 Answers 2

1

Include js.js first then your jQuery code. I will suggest make sure that while executing jQuery code your other file should be loaded.

As you are defining fun() function globally you can call it directly.

if ( slotNumber == cardNumber ) {
  ui.draggable.addClass( 'correct' );
  ui.draggable.draggable( 'disable' );
  $(this).droppable( 'disable' );
  ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' }  );
  ui.draggable.draggable( 'option', 'revert', false );
  correctCards++;
  count ++;
  fun();
} 
Sign up to request clarification or add additional context in comments.

Comments

1

This is no difference from normal function call. Just put fun() in jQuery and include the scripts in the same html file where the js file comes first

Comments

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.