1

I have a page where I show some text. I want to hide that text and show it only when someone clicks a link/button. I tried using this:

<script>
    function f()
    {          
      document.getElementById("line").focus();
      document.getElementById("help").innerHTML = helptext();
    }

    $(function(){
       $('p[id=help]').hide();
       $('a[title=showcmd]').click(function(){
            $('p[id=help]').slideIn();
            $(this).hide();
            f();
       });
    });

    </script>

But it is not working.

17
  • Yes. I just forgot to add that. Now you can check. I have edited the question. Commented Jan 2, 2013 at 11:57
  • Are you sure your listener is called? Commented Jan 2, 2013 at 11:57
  • 3
    Looks fine to me... is helptext defined anywhere? Please create a jsfiddle.net demo. Commented Jan 2, 2013 at 11:58
  • Yes. It is defined. And it is rendering well if I just call the function on body load. Commented Jan 2, 2013 at 11:58
  • 2
    As @dystroy hinted at, slideIn is not standard jQuery. I guess the code errors there (the console will tell you). Commented Jan 2, 2013 at 12:00

4 Answers 4

4

Change:

$('p[id=help]').slideIn();

To

$('p[id=help]').slideDown();

There's no slideIn in jquery

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

Comments

2

As the console shows, there is no slideIn function in jQuery :

Uncaught TypeError: Object [object Object] has no method 'slideIn'

tested code :

function f()
    {          
      document.getElementById("help").innerHTML = "Trying out Jquery";
    }

$(function(){
   $('p[id=help]').hide();
   $('a[title=showcmd]').click(function(){
        $('p[id=help]').slideIn();
        $(this).hide();
       f();
   });
});

I suppose you wanted to use slideUp or slideDown, or maybe fadeIn.

For future problems, I'd suggest you to look at the developer console : it always shows the error message, most often in a clear enough way with the exact location in your code.

2 Comments

I think I was using the wrong function. But still when I am using .fadeIn(), it is still not working on my page though on fiddlejs it is working. Thank you for immense help.
Hi All, It is working now. Some problem with cache was preventing from the changes to load. Thank you all.
1

If its not work then try to prevent the click event as below.

<script>
    function f()
    {          
      document.getElementById("line").focus();
      document.getElementById("help").innerHTML = helptext();
    }

    $(function(){
       $('p#help').hide();
       $('a[title=showcmd]').click(function(e){
            e.preventDefault();
            $('p#help').slideDown('slow');
            $(this).hide();
            f();
       });
    });

    </script>

Comments

0

Use slideDown() instead of slideIn()

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.