tags:

views:

81

answers:

3

I have a simple ASP.Net form with the following unordered list:

<ul id="ctl00_ContentPlaceHolder1_BulletedList1">
    <li>No Lines Added</li>
</ul>

When a user begins filling out other parts of the form, I want to remove this single <LI> and begin populating the list with other <LI> elements. The code below is how I am doing the removal:

function commitLine() {
    //if "No Lines Added" is the only item, remove all items, otherwise
    //continue with the additional item
    if ($("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text() == "No Lines Added") {
        $("#ctl00_ContentPlaceHolder1_BulletedList1 li").remove();
    }
    //code that begins the list population
}

Now, this code works great in every browser except IE8 (presumably IE7, IE6 as well). I've been staring at this for hours and can't sort it out. Does anyone have an idea as to the problem here?

A: 

I believe IE doesn't support nth-child.

http://msdn.microsoft.com/en-us/library/cc351024%28VS.85%29.aspx

edl
jQuery (well, Sizzle) handles that in browsers that don't support it.
x1a4
When I alert the nth child statement, it properly displays the value so that can be ruled out.
Tehrab
A: 

Is $("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text() returning text surrounded by whitespace in IE? If so, change that fragment to $.trim($("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text()) to remove it.

x1a4
Yep, this was the issue, thanks!
Tehrab
Nice. I've felt your pain before.
x1a4
A: 

I added this two lines of code, and your code works fine:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8">
</head>
DS