Home Web Front-end JS Tutorial How to dynamically add and delete elements with jQuery_jquery

How to dynamically add and delete elements with jQuery_jquery

May 16, 2016 pm 05:04 PM
Delete element Add element

复制代码 代码如下:

<script> <br>$.schoolFn = { <br>addItem: function(obj){ <br>$("#itemList").append("<li id='liItrm' class='list-group-item clearfix'><span class='glyphicon glyphicon-resize-vertical sort-handle'></span>" obj "<input type='hidden' name='audiences' value='" obj "'><button type='button' class='close delete-btn deleteItem' onclick='deleteItem(this);' title='删除'>×</button></li>"); <br>}, <br><br>removeItem: function(obj){ <br>$("#" obj).replaceWith(""); <br>} <br>} <br>$("#itemAdd").click(function(){ <br>var item=$('#teacherInput').val(); <br>$.schoolFn.addItem(item); <br>$('#teacherInput').val(""); <br>}); <br>function deleteItem(obj){ <br>var item=$(obj).parents(".list-group-item").attr("id"); <br>$.schoolFn.removeItem(item); <br>} <br></script>
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)

How to delete elements but keep child elements in jquery How to delete elements but keep child elements in jquery Nov 19, 2021 pm 02:22 PM

How to delete elements but keep child elements in jquery: 1. Use the children() method to get all the child elements of the specified element; 2. Use the unwrap() method to delete the parent element of the child element but keep the child elements. The syntax "$(" specifies the element. ").children().unwrap();".

How to delete elements from set in javascript How to delete elements from set in javascript Jan 12, 2022 am 10:56 AM

Methods to delete elements: 1. Use delete() to delete the specified element from the Set object, the syntax is "setObj.delete(value);"; 2. Use clear() to delete all elements in the Set object, the syntax is "setObj.delete(value);" "setObj.clear();".

Java program to add elements to LinkedList Java program to add elements to LinkedList Aug 26, 2023 pm 10:21 PM

LinkedList is a general class of JavaCollectionFramework, which implements three interfaces: List, Deque and Queue. It provides the functionality of the LinkedList data structure, a linear data structure in which each element is linked to each other. We can perform a variety of operations on a LinkedList, including adding, removing, and traversing elements. To add elements to the LinkedList collection, we can use various built-in methods such as add(), addFirst(), and addLast(). We will explore how to use these methods to add elements to a LinkedList. in Java

How to delete an element with a specified key in a PHP array How to delete an element with a specified key in a PHP array Jul 07, 2023 pm 11:15 PM

How to delete an element with a specified key name in a PHP array In PHP development, array is a very important data structure. When operating an array, you often encounter situations where you need to delete elements with specified key names. This article will use code examples to introduce how to delete elements with specified key names in PHP arrays. PHP provides a variety of methods to delete elements in an array. Three of the commonly used methods are introduced below. Method 1: Use the unset() function The unset() function can be used to destroy specified variables, including elements in the array.

Use the array_pop() function in PHP to delete the last element of the array Use the array_pop() function in PHP to delete the last element of the array Nov 18, 2023 pm 12:45 PM

The array_pop() function in PHP is used to delete the last element of the array. This article will introduce the use of array_pop() function in detail and provide relevant code examples. In PHP, array is a very commonly used data structure used to store multiple related data. Sometimes, we may need to remove an element from the end of an array. At this time, you can use the array_pop() function to complete this operation. The syntax of the array_pop() function is as follows: mixedar

Python program: add elements to first and last position of linked list Python program: add elements to first and last position of linked list Aug 23, 2023 pm 11:17 PM

In Python, a linked list is a linear data structure that consists of a sequence of nodes, each node containing a value and a reference to the next node in the linked list. In this article, we will discuss how to add elements to the first and last position of a linked list in Python. LinkedList inPython A linked list is a reference data structure used to store a set of elements. It is similar to an array in a way, but in an array, the data is stored in contiguous memory locations, whereas in a linked list, the data is not subject to this condition. This means that the data is not stored sequentially but in a random manner in memory. Thisraisesonequestionthatis,howwecanac

C++ program to remove the smallest element from both sides so that the 2* minimum value is greater than the maximum value C++ program to remove the smallest element from both sides so that the 2* minimum value is greater than the maximum value Aug 28, 2023 am 08:09 AM

The problem involves removing elements from either side of a list of integers in such a way that 2*min is greater than max. vector<int>arr={250,10,11,12,19,200};res=solve(arr);We can use brute force method. We can try all possible satisfactions and find the longest subarray that satisfies the 2*min>max condition. We can also use dynamic programming methods to try all possible excessive and unwanted subarray combinations. Example (using vector ADT) Let's say we have an array like "[250,10,11,12,19,200]". To get the best solution we need to remove elements [250,200

Tips and things to note when adding elements to an array in Java Tips and things to note when adding elements to an array in Java Jan 03, 2024 pm 02:01 PM

Tips and precautions for adding elements to arrays in Java In Java, arrays are a very common and important data structure. It can store a set of elements of the same type, and these elements can be accessed and modified through indexes. In practical applications, we often need to dynamically add elements to an array. This article will introduce some tips and precautions for adding elements to arrays in Java, and provide corresponding code examples. Use dynamic array (ArrayList) to add elements Dynamic array ArrayList is

See all articles