Home >Web Front-end >Front-end Q&A >How to delete the last li of UL in JQuery

How to delete the last li of UL in JQuery

藏色散人
藏色散人Original
2021-11-15 10:50:512485browse

JQuery method to delete the last li of UL: 1. Create a new html file; 2. Create a list using ul and li tags; 3. Create a button using the button tag and bind the onclick click event to the button. ;4. Delete it by creating the delli() function.

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!

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
Previous article:What is jquery lengthNext article:What is jquery length