Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove li with a spesific id in Jquery

Posted on 2011-09-07
7
Medium Priority
?
637 Views
Last Modified: 2012-05-12
I needto remove li with a specific id but it does not work..

Here is what I using
$("li[@id=" + $(this).val() + ']').remove();
0
Comment
Question by:erikTsomik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36496867
$("li#" + $(this).val()).remove();

should work (a unique ID per element) :
$("#" + $(this).val()).remove();

0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36496874
I use this and it works
$("li[id=" + $(this).val() + ']').remove();
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36496882
the ID selector is : #

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 19

Author Comment

by:erikTsomik
ID: 36496896
My html code is this . How would I remove all elements not just li but ul an label
<label></label>
<ul class="options">
<li id="1">John</li>
</ul>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36496913
Why a new question?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36496923
it just a part of it
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36497103
erikTsomik thanks for your answer.

I suppose you want to remove label and ul around the given LI

    <label></label>
    <ul class="options">
         <li id="1">John</li>
    </ul>

I think you shoud use a container for all :

<div class=".containerClass">
    <label></label>
    <ul class="options">
         <li id="1">John</li>
    </ul>
</div>

and now you can use :

$("#" + $(this).val()).closest(".containerClass").remove(); // or if you really prefer your syntax (not recommended) : $("li[id=" + $(this).val() + ']').closest(".containerClass").remove();

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question