here is a code snippet where we always animate one <div>
and hide()
the rest. This produces a long list of hide()
as we add more.
<script type="text/javascript">
//<![CDATA[
function showSlidingDivVideoCategory(){
// show what we need
$("#slidingDivVideoCategory").animate({"height": "toggle"}, { duration: 500 });
// hide what we dont
$("#slidingDivAudioCategory").hide();
$("#slidingDivPicturesCategory").hide();
$("#slidingDivAdsCategory").hide();
$("#slidingDivMediaRoom").hide();
$("#slidingDivKeynotePresentations").hide();
$("#slidingDivBlog").hide();
$("#slidingDivAbout").hide();
$("#slidingDivSubmitFootage").hide();
$("#slidingDivContact").hide();
$("#slidingDivSearchBox").hide();
Is there a way that I can hide()
all <div>
so I can just then show the few I want and animate
the one I want?
摆脱个别的hide语句并使用:
$("div:not('#slidingDivVideoCategory')").hide();
If you really want to hide all <div>
s, use
$('div').hide();
However, you might want to add a class to all <div>
s you want to be hidden add use
$('.yourclassname').hide();
instead.
You can use a class selector and hide using class.
$(".myclass").hide();
Or combine multiple selectors:
$("#slidingDivAudioCategory, #slidingDivPicturesCategory, #slidingDivsAdsCategory").hide();
Look you can use advance selectors, I saw you have many ids starting by the same word so this would work
$("[id*=slidingDiv]").hide();
//For the animate use what you have
Hope it helped!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.