jquery dynamically deletes the same object with ID, deletes the same type of object dynamically

Source: Internet
Author: User

Here's a look at this example:

The code is as follows Copy Code


<input type= "hidden" name= "attr_value_list[" "Rel=" "4" all= "4" "Value=" ">
<input type= "hidden" name= "attr_value_list[" "Rel=" "4" all= "4" "Value=" ">
<input type= "hidden" name= "attr_value_list[" "Rel=" "4" all= "4" "Value=" ">
<input type= "hidden" name= "attr_value_list[" "Rel=" "4" all= "4" "Value=" ">

Now, what if you want to delete one of the input?

The original method:

The code is as follows Copy Code


function Delrow (WHO) {
$ ("Input:hidden[name= ' attr_value_list[]"). Remove ();
}

So all the objects are deleted. Obviously, it won't work.

Right way:

The code is as follows Copy Code
function Delrow (WHO) {
$ ("Input:hidden[name= ' attr_value_list[] ']:last"). Remove ();
}

This is the last one to delete the object. What if you want to delete more than one?


Such

The code is as follows Copy Code
for (i=0;i<num;i++)
{
$ (' input:hidden[all= "' +id+ '"]:last '). Remove ();
}

Num Here is the number of deletes


This will enable you to delete multiple objects pull!

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.