Question: I have a menu consisting of a couplde of `<ul>`s nested within a couple of `<li>`s. eg:

```
<ul>
<li><a href="somewhere.html">Item 1</a></li>
<li><a href="somewhere.html">Item 2</a></li>
<li><a href="somewhere.html">Item 3</a>
  <ul>
    <li><a href="somewhere.html">Sub Item 1</a></li>
    <li><a href="somewhere.html">Sub Item 2</a></li>
  </ul>
</li>
</ul>

```

For the `<li>`s with nested `<ul>`s I want to replace their `href` attributes with #, eg:

```
<li><a href="somewhere.html">Item 2</a></li>
<li><a href="#">Item 3</a>
      <ul>
        <li><a href="somewhere.html">Sub Item 1</a></li>

```

I have written this script to do that, but it seems to affect all a tags within both lists.

```
$.each($("#menu ul li"), function() {
  if($(this).has("ul")){
   $(this).find("a").attr("href", "#");
  };
});

```

Was wondering if some one could tell me where Ive gone wrong?

Answer: 
What's wrong with just looping through them again?

```
function nxt2(e:MouseEvent)
{
    removeChild(half2);
    for (var i:int = 0; i < caw1.length; i++) {
        removeChild(caw[i]);
    }
    half2.removeEventListener(MouseEvent.CLICK, nxt2);
}

```
FP 11 later , A new method has been added. that is [`removeChildren()`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#removeChildren%28%29). using a `removeChildren()` rather than using for loop with `removeChild()`. is more reasonable.

> 
> Removes all child DisplayObject instances from the child list of the
>  DisplayObjectContainer instance. The parent property of the removed
>  children is set to null , and the objects are garbage collected if no
>  other references to the children exist.
> 
> 
> The garbage collector reallocates unused memory space. When a variable
>  or object is no longer actively referenced or stored somewhere, the
>  garbage collector sweeps through and wipes out the memory space it
>  used to occupy if no other references to it exist.
> 
> 
> 

Try this:

```
function nxt2(e:MouseEvent)
{
    removeChild(half2);
    removeChildren(0,caw1.length-1);
    half2.removeEventListener(MouseEvent.CLICK, nxt2);
}

```