Home >Web Front-end >JS Tutorial >Use jquery to implement tab switching example code of div_jquery

Use jquery to implement tab switching example code of div_jquery

WBOY
WBOYOriginal
2016-05-16 17:33:161113browse

jQuery implements Tab switching. The simple effect of js code written not long ago by contacting jQ is now written in jQ:
HTML code:

Copy Code The code is as follows:



css code:
Copy code The code is as follows:

#sidebar-tab{border:1px solid #ccf;margin-bottom:1.5em;overflow :hidden;}
#tab-title h3{color:#666;font-size:15px;font-weight:400;}
#tab-title .selected{color:#356aa0;border-bottom: 0px;} /*Style when the title is selected*/
#tab-title span{padding:5px 9px 5px 10px;border:1px solid #ccf;border-right:0px;margin-left:-1px;cursor :pointer;}
#tab-content .hide{display:none;} /*The first piece of content is displayed by default, and the rest are hidden*/
#tab-content ul{padding:5px 10px;overflow:hidden ;}
#tab-content ul li{padding-top:5px;height:20px;}

jQ code:
Copy code The code is as follows:



It is very convenient to write with jQ; first find the child element in the ID to add the event click introduces the function; after finding the sibling element, removeClass(); let other sibling elements display: "none";

The following is the original jQ code:

Copy code The code is as follows:

<script> <br><br>$('#tab-title span').click(function(){ $(this).addClass("selected").siblings().removeClass(); $("#tab-content > ul").slideUp('1500'). eq($('#tab-title span').index(this)).slideDown('1500') <br>}); <br></script>

When you Clicking the current event after triggering the current event will still trigger it; there is no need to trigger the event (this) when clicking the current event;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn