开发者

jQuery slideToggle adding mysterious margin to parent <li>

开发者 https://www.devze.com 2023-04-12 17:03 出处:网络
I\'ve got a <ul> with 5 <li> items. Each list item has a headline and a paragraph. I\'m using slideToggle() to display the paragraph when you click the headline.

I've got a <ul> with 5 <li> items. Each list item has a headline and a paragraph. I'm using slideToggle() to display the paragraph when you click the headline.

But, when you click the headline a second time the slideToggle() hides the paragraph but adds some white space to the <li>. The more I click the headline to toggle the paragraph, the more white space appears.

The jQuery:

$(documen开发者_运维技巧t).ready(function(){
        $('#content ul li h3').click(function(){
            $(this).next('p').slideToggle('fast');
        }) 
    });

My CSS:

#content ul li p {
            display:none;
        }

My HTML:

<div id="content"> 
  <ul class="faq">
        <li>
            <h3>Headline</h3>
            <p>Paragraph Text<br>More text...</p>
        </li>
  </ul>
</div>


Here was the trouble..

In my Global style sheet I had .faq li { display:inline; }

Once I removed this everything worked exactly as it should.

0

精彩评论

暂无评论...
验证码 换一张
取 消