0

I was trying to add function2 in my jquery hide method.I can do it through the code which is commented.So,can anyone please rectify my code.I want to call function2 from callback parameter of hide method.

<script>
//        $(document).ready(function () {
//            $("#p1").click(function () {
//                $("#p2").hide("slow", function () {
//                    alert("para2 is now hidden");
//                });
//            });
//        });

$(document).ready(function () {
    $("#p1").click(function () {
        $("#p2").hide("slow", function(){
            function2(); 
        });
    });

function function2() {
    alert("para2 is now hidden");
}
</script>
2
  • Now that I've properly indented your code, do you realise the problem? Commented Feb 18, 2014 at 12:05
  • What is wrong with this code it seems to be working just need to complete the $(document).ready() jsfiddle.net/8RvCs Commented Feb 18, 2014 at 12:08

3 Answers 3

1

Problem is, you have a syntax error because you haven't closed your $(document).ready() function or method:

$(document).ready(function () {
    $("#p1").click(function () {
        $("#p2").hide("slow", function(){
            function2(); 
        });
    });
});

JSFiddle

As already mentioned, you can just pass the function's reference if that is all that should be in the callback:

$("#p2").hide("slow", function2);
Sign up to request clarification or add additional context in comments.

Comments

1

The problem with your code is, you forgot to close the ready event handler,

   $(document).ready(function () {
     $("#p1").click(function () {
        $("#p2").hide("slow", function(){
            function2(); 
        });
    });
   });

And you can also try this code to improvise your code much better,

   $("#p1").click(function () {
     $("#p2").hide("slow", function2);
   });

Comments

0

if I understand, just pass the function that you want

 $("#p1").click(function () {
            $("#p2").hide("slow", function2);
    });

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.