How to delete the last li of UL in JQuery

藏色散人
Release: 2021-11-17 11:23:14
Original
1978 people have browsed it

JQuery method to delete the last li of UL: 1. Use the ul li tag to create a list; 2. Use the button tag to create a button and bind the onclick click event to the button; 3. Through the jquery selector ": last" to get the last li and delete it using the remove method.

How to delete the last li of UL in JQuery

The operating environment of this article: Windows7 system, jquery3.2.1 version, DELL G3 computer

How to delete the last li of UL with JQuery?

Create a new html file, named test.html, to explain how jquery deletes the last li element.

How to delete the last li of UL in JQuery

In the test.html file, use the ul and li tags to create a list for testing.

How to delete the last li of UL in JQuery

In the test.html file, set the id of the ul tag to mytest, which is used to obtain the ul object below.

How to delete the last li of UL in JQuery

In the test.html file, use the button tag to create a button, bind the onclick click event to the button, and when the button is clicked, execute the delli() function.

How to delete the last li of UL in JQuery

In the js tag, create the delli() function. Within the function, obtain the last li tag object through the jquery selector ":last" and use the remove() method Delete it.

How to delete the last li of UL in JQuery

Open the test.html file in the browser, click the button to view the results.

How to delete the last li of UL in JQuery

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to delete the last li of UL in JQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!