Native js implements the news list to expand/collapse the full-text function, and js News list

Source: Internet
Author: User

Native js implements the news list to expand/collapse the full-text function, and js News list

Knowledge points

1. The implementation principle is very simple. by clicking the tag, you can set the display attribute of the div to hide or display,

It is mainly about dom operations.

2. dom operations:

ParentNode obtains the parent Element

NextSibling

Previussibling

3. Notes:

Consider that when you click to expand the full text, other expanded full text will be collected.

When nextSibling is used to obtain the next node, different browsers may have different judgments.

Some get elements, some get line breaks or spaces, so here we need to use nodeType to determine whether the data type nodeType only returns numbers 1, 2, 3

The element node is obtained only when 1 is returned.

(I didn't take this issue into consideration when I did it. I thought it was a long time ago)

In addition, js does not have dom operations like getting all elements of the same level in jquery, so I wrote a siblings (elm)

It can also be used in the future.

Complete code

<! DOCTYPE html> 

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.