Home Web Front-end JS Tutorial Make a simple accordion with jQuery

Make a simple accordion with jQuery

Jan 12, 2018 am 09:45 AM
jquery make accordion

This article mainly introduces the simple production of jQuery accordion in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

First of all, let’s make a simple jQuery rendering. The specific content is as follows

The css code is as follows:


<style type="text/css" media="screen">
  *{margin: 0;padding: 0;}
  ul,li{list-style:none}
   ul {
    width: 300px;
    background: yellow;
    margin: 50px auto;
  }
  ul>li{
    line-height: 50px;
    text-align: center;
    border-bottom: 1px solid #ccc;
  }
  ul>li>ol{
    background: blue;
    display: none;
  }
  ul>li>ol>li{
    line-height: 50px;
  }
</style>
Copy after login


HTML code is as follows:


<ul id="ul">

  <li>
    <p>jquery的核心函数</p>
    <ol>
      <li>jQuery([selector,[context]])</li>
      <li>jQuery(html,[ownerDoc])1.8</li>
      <li>jQuery(callback) </li>
      <li>jQuery.holdReady(hold)1.6+</li>
    </ol>
  </li>
  <li>
      <p>jQuery的效果</p>
    <ol>
      <li>hide 显示和隐藏</li>
      <li>slideDown 只对高度有效</li>
      <li>fadeIn 淡入效果</li>
      <li>slideToggle 淡入和淡出效果</li>
    </ol>
  </li>
  <li>
      <p>jQuery的属性</p>
    <ol>
      <li>attr 设置或返回的元素</li>
      <li>removeAttr 从每个元素中删除一个元素</li>
      <li>prop 获取第一个元素的属性</li>
      <li>removeProp prop()方法设置属性集</li>
    </ol>
  </li>
  <li>
      <p>jQuery的事件</p>
    <ol>
      <li>off 在元素上移除多个事件的处理函数</li>
      <li>bind 为每个元素绑定事件处理函数</li>
      <li>one 为每个匹配元素绑定一次性处理函数</li>
      <li>trigger 在每个匹配的元素上触发某类事件</li>
    </ol>
  </li>

</ul>
Copy after login


##jQuery code is as follows:


<script src="jquery.min.js" type="text/javascript"charset="utf-8"></script>
<script type="text/javascript">
 $("#ul>li>p").click(function(){

  $(this).nextAll().slideDown()
  .end().parent().siblings()
  .children("ol").hide();
 }); 
</script>
Copy after login


The rendering is as follows:

Related recommendations:

JQuery implements simple Accordion effect example sharing

Example detailed explanation jQuery implements accordion menu, hierarchical menu, top menu, seamless scrolling effect

jQuery implements drop-down menu Accordion effect sharing

The above is the detailed content of Make a simple accordion with jQuery. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Specific method to create film movement effect in PPT Specific method to create film movement effect in PPT Mar 26, 2024 pm 04:00 PM

1. Start PPT, create a new blank document, select all text boxes and delete them. 2. Execute the Insert-Shape command, drag a rectangle in the document, and fill the shape with black. 3. Drag the rectangle to elongate it, execute the Insert-Shape command, drag out the small square, and set the fill color to white. 4. Copy and paste the small squares one by one so that the top and bottom are evenly distributed on both sides of the film. After selecting them all with ctrl+a, right-click and select Group. 5. Execute the Insert-Picture command, find the picture to be inserted in the pop-up dialog box, click to open, and adjust the size and position of the picture. 6. Repeat step 5 to insert and set the remaining pictures in order to form a film picture. 7. Select the film, execute animation-add animation command

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Let me teach you! How to create animation effects in PPT! Let me teach you! How to create animation effects in PPT! Mar 20, 2024 pm 06:40 PM

When making PPT, using some animation effects will make it more lively and cute than without using animation effects. With the addition of animation effects, people may like to watch this PPT, so we must learn how to create animation effects for PPT. Next, I will introduce in detail how to add animation effects to PPT. Please continue reading and study these steps carefully. I believe they will be helpful to you! First, open the PPT we made ourselves. You will notice that this PPT currently does not have any animation effects (as shown by the red arrow in the picture below). 2. Then, we need to add animation effects to the picture. We first select the picture, and then click the [Animation] button on the menu bar (as shown in the red circle in the figure below). 3. Next, we click inside the animation

How to make a word cover How to make a word cover Mar 19, 2024 pm 06:50 PM

A graduation thesis must have a cover, a table of contents, an end, etc. Only then can the thesis be complete. In the last issue, the editor has shared with friends how to make a table of contents in Word. In this issue, I will share with you how to make a word cover. If you don’t know how to make it, hurry up! 1. First, we open the word document we want to make a cover, as shown in the figure below: 2. Then, we click the [Chapter] button on the menu bar and select the cover page. This function is equivalent to a cover library, in which you can Choose a suitable and beautiful cover by yourself, as shown in the red circle in the picture below: 3. After clicking, you can see various types of covers, such as business type, suitable for company contracts and documents; resume type, suitable for job hunting and submission of resumes Friends, wait, okay?

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

See all articles