Solved

Jquery - .remove() bug

Posted on 2011-09-21
4
203 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use Mid in Html 6 21
Accordion won't close correctly 5 12
how can i break an array into a couple 5 22
Slush on text 2 8
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

685 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