Solved

remove li with a spesific id in Jquery

Posted on 2011-09-07
7
620 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
  • 4
  • 3
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting dates in JavaScript 2 37
how can i test my code? 1 42
key press alert 2 19
Question about traversing a tree using jQuery 7 18
This article will show, step by step, how to integrate R code into a R Sweave document
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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