Solved

Jquery - .remove() bug

Posted on 2011-09-21
4
198 Views
Last Modified: 2012-05-12
I'm trying to remove empty UL tags using Jquery below:

$("ul").each(function(){
     if ($(this).find("li").length == 0) {
     $(this).remove();
     // $(this).css("border","20px solid red");
     }
});

The strange thing is the $(this).remove(); doesn't work, whereas $(this).css("border","20px solid red"); in the code above works!

Are there any known bugs with .remove() ?  
0
Comment
Question by:jeremyll
  • 2
4 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36573673
your code is working..
I dont see any bugs and is doing what it has to do..

BR-Sudhindra-www.clicksperday.com
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36573677
please provide the html
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36573694
here is the working one..

http://jsfiddle.net/Sudhindra/6hybe/

Please post the complete code (html)...

BR- Sudhindra-www.clicksperday.com
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 36580117

// Not quite what you what but try this instead:

$(this).css( {display: "none"} );
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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

803 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