0

I am trying to call my JavaScript Function from my jQuery Function, but it does not seem to be calling the function showMain() at the end of the jQuery.

See below: I am trying to Call the showMain() function at the end of the .click function. Code:

$(document).ready(function () {  
        $('.slideshowExit').click(function () {
                setTimeout(function() {
                    $("#welcomeText").fadeOut(2000);
                },1000);
            $("#welcomePage").css("display", "none");

            //The function I am trying to Call
            showMain();
            });    




    function showMain() {
        var main= document.getElementById("mainDiv");
        main.style.display = 'block';
6
  • make fiddle, or post HTML as well Commented Oct 27, 2017 at 4:58
  • 1
    Define function before calling from jquery Commented Oct 27, 2017 at 4:59
  • But showMain should be hoisted (function hoisting). Commented Oct 27, 2017 at 5:01
  • 2
    It should work..Look at the fiddle jsfiddle.net/bLjLz0m5/1 In your case it is not working because of other conditions or errors Commented Oct 27, 2017 at 5:02
  • Just cleanup and align your code correctly and you'll see the errors by yourself. Commented Oct 27, 2017 at 5:06

3 Answers 3

4

You should use an anonymous function.

$(document).ready(function () {
    $('.slideshowExit').click(function () {
        setTimeout(function () {
            $("#welcomeText").fadeOut(2000);
        }, 1000);
        $("#welcomePage").css("display", "none");

        //The function I am trying to Call
        showMain();
    });
});


var showMain = function () {
    var main = document.getElementById("mainDiv");
    main.style.display = 'block';
};
Sign up to request clarification or add additional context in comments.

Comments

1

There is a mistake with your function definition. Please use the closing "}" bracket after the function.

I am trying to call my JavaScript Function from my jQuery Function, but it does not seem to be calling the function showMain() at the end of the jQuery.

See below: I am trying to Call the showMain() function at the end of the .click function. Code:

$(document).ready(function () {  
    $('.slideshowExit').click(function () {
       setTimeout(function() {
       $("#welcomeText").fadeOut(2000);
    },1000);

    $("#welcomePage").css("display", "none");
    //The function I am trying to Call
    showMain();
 });    

function showMain() {
    var main= document.getElementById("mainDiv");
    main.style.display = 'block';
}

Comments

1

Runnable Code:

$(document).ready(function () {
    $('.slideshowExit').click(function () {
        setTimeout(function () {
            $("#welcomeText").fadeOut(500);
        }, 1000);
        $("#welcomePage").css("display", "none");

        //The function I am trying to Call
        showMain();
    });
})



    function showMain() {
        var main = document.getElementById("mainDiv");
        main.style.display = 'block';
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

<div class="slideshowExit">
  Click Here
</div>

<div id="mainDiv">
  <div id="welcomeText">Welcome to India</div>
</div>

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.