jQuery & CSS - Remove/Add display:none

前端 未结 13 2453
遥遥无期
遥遥无期 2020-12-12 12:37

I have a div with this class :

.news{
  width:710px; 
  float:left;
  border-bottom:1px #000000 solid;
  font-weight:bold;
  display:none;
}
<
13条回答
  •  余生分开走
    2020-12-12 12:57

    So, let me give you sample code:

    Blah, blah, blah. I'm hidden.
    Hide/Show News

    The link will be the trigger to show the div when clicked. So your Javascript will be:

    $('.trigger').click(function() {
       $('.news').toggle();
    });
    

    You're almost always better off letting jQuery handle the styling for hiding and showing elements.

    Edit: I see people above are recommending using .show and .hide for this. .toggle allows you to do both with just one effect. So that's cool.

提交回复
热议问题