最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Onclick Display Block to None and None to Block - Stack Overflow

programmeradmin2浏览0评论

I have this code: CSS:

 .hiddenlinks{display: none;}

HTML:

<div id="expand">

<a href="javascript://" class="business" >123</a>
    <div class="hiddenlinks">
         <a href="/"target="_blank" class="business" style="color:#f36523">ABC</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">DEF</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">HIJ</a>
    </div>
 </div>

There is a list of similar div ids in a vertical order. What I am trying to do is once "123" is clicked, the divs id under #expand will shift down and the "ABC", "DEF", and "HIJ" will display:block.

So my question is a two parter:

  1. How can i toggle display block and none on click with this html?
  2. Is there a way to animate the separation of the div id's once .hiddenlinks goes from display:none to display:block. and also when .hiddenlinks goes back to display:none and the div ids close the gap.

I have this code: CSS:

 .hiddenlinks{display: none;}

HTML:

<div id="expand">

<a href="javascript://" class="business" >123</a>
    <div class="hiddenlinks">
         <a href="/"target="_blank" class="business" style="color:#f36523">ABC</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">DEF</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">HIJ</a>
    </div>
 </div>

There is a list of similar div ids in a vertical order. What I am trying to do is once "123" is clicked, the divs id under #expand will shift down and the "ABC", "DEF", and "HIJ" will display:block.

So my question is a two parter:

  1. How can i toggle display block and none on click with this html?
  2. Is there a way to animate the separation of the div id's once .hiddenlinks goes from display:none to display:block. and also when .hiddenlinks goes back to display:none and the div ids close the gap.
Share Improve this question edited Dec 15, 2011 at 18:12 James Montagne 78.8k14 gold badges114 silver badges132 bronze badges asked Dec 15, 2011 at 16:53 Jean HulesJean Hules 4153 gold badges6 silver badges12 bronze badges 2
  • sorry where is the #expand div? – microspino Commented Dec 15, 2011 at 16:59
  • you should view the topic and use toggle visibility (javascript function) to change display none settings: stackoverflow./a/15636682/2131877 – T.Todua Commented Mar 26, 2013 at 12:09
Add a ment  | 

1 Answer 1

Reset to default 4

http://jsfiddle/F5NCt/1/

<head>
    <script src="//ajax.googleapis./ajax/libs/jquery/1.8.3/jquery.min.js"><<<< this goes in the header 
</script>
<script>
$(document).ready(function(){
  $(".business").click(function(){
    $(".hiddenlinks").slideToggle();
  });
});
</script>
</head>
<body>

    <div id="expand">

<a href="javascript://" class="business" >123</a>
    <div class="hiddenlinks">
         <a href="/"target="_blank" class="business" style="color:#f36523">ABC</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">DEF</a><br />
         <a href="/"target="_blank" class="business" style="color:#f36523">HIJ</a>
    </div>
 </div>
</body>





    .hiddenlinks { 
display:none;
}

i have created a example for you i hope it helps once you click 123 the options drop down to your second question i m not sure but i think if you will have different id divs for each of your hidden link then in .slideToggle(//inside here you can customise how each div is shown\);

please see

www.jquery.

also see the example above

hope it helps you

发布评论

评论列表(0)

  1. 暂无评论