April 10, 2012

Jquery Toggle Slider & Toggle Text

Question by Jay J.

I’m trying to slide down a div after the “Show” link is clicked and change that text to “Hide” but it doesn’t seem to work so well.

<div id="mobilemenu"><a id="#menutoggle" href="#">Show</a></div>
<div id="slider">Content to slide in under #mobilemenu</div>

I tried solving with some of the other StackOverflow answers, but I couldn’t get it to work so not sure what I’m doing wrong.

Answer by Starx

Update your anchor. Remove the # from the id and attach an event handler.

$("#menutoggle").click(function() {
    $("#slider").toggle();
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!