1

i have the following script that shows a div when a link is clicked...

$(document).ready(function() {
            $('.accordion ul li h1').click(function() { $(this).parent().parent().find('.ac:visible').slideToggle().parent().removeClass('active'); if ($(this).next().is(':hidden')) $(this).next().slideToggle().parent().addClass('active'); });
        });

I also have a div on my page

<div id="shortinfo">short info</div> 

How would i go about setting short info to didssapear when the link is clicked,, and reappear once its clicked again?

I tried adding

<h1 onclick="document.getElementById('shortinfo').style.display='none'">

but then i need it to reappear once its clicked again?


this is my new code, doesnt seem to work witht he toggle

 $(document).ready(function() {
            $('.accordion ul li h1').click(function() { $(this).parent().parent().find('.ac:visible').slideToggle().parent().removeClass('active'); if ($(this).next().is(':hidden')) $(this).next().slideToggle().parent().addClass('active'); });
            $('#shortinfo').toggle();

        });

2 Answers 2

3

As you are using JQuery, you can use Toggle method to display or hide the element: http://api.jquery.com/toggle/

You could then do the following:

$('#shortinfo').toggle();

To integrate it with your h1 onclick, it would become:

<h1 onclick="$('#shortinfo').toggle()">
Sign up to request clarification or add additional context in comments.

7 Comments

There must be something else wrong than. Toggle is the way to go here.
I know have $(document).ready(function() { $('.accordion ul li h1').click(function() { $(this).parent().parent().find('.ac:visible').slideToggle().parent().removeClass('active'); if ($(this).next().is(':hidden')) $(this).next().slideToggle().parent().addClass('active'); }); $('#shortinfo').toggle(); });
Have you tried to replace your whole h1 with the latest code sample I've posted ? What version of JQuery are you using ?
ahh that h1 worked :) is there a way to have it set to display block at first, then dissapear on click?\
Make it visible via CSS then toggle() will take care of the rest: if visible it will hide it and show it otherwise.
|
1

delete that onclick

$("#shortinfo").toggle();

2 Comments

I need the shortinfo to toggle display
@alicepractice: yes this does exacly you need

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.