Помогите разобраться что я не так делаю, мне нужно в контейнере удалить элементы определенного типа, в даном случае <img> если делаю так с алертом - выводит 7 штук:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function RemoveEl(ContainerElementId, RemoveElementType)
{
var tmpdoc = document.getElementById(ContainerElementId);
var oc=tmpdoc.getElementsByTagName(RemoveElementType)
alert('Всего найдено: ' + oc.length)
for (var i=0; i<oc.length; i++)
{
alert(oc[i]);
//oc[i].parentNode ? oc[i].parentNode.removeChild(oc[i]) : oc[i];
}
};
</script>
</head>
<body>
<button onclick="RemoveEl('ServiceCatalog', 'img');">Run</button>
<div id="ServiceCatalog">
<fieldset id="X15" widgettype="group" class="groupBox">
<legend id="X15Legend">
<span class="caption" id="X15Caption">
Service Catalog
</span>
</legend>
<div id="X21">
<img src="servlet/image?application=joinsvcDisplay&topic=Employee+Lifecycle+Services&type=img&key=j3gzV0NsEk6fQw6ZjH2%2Fdg&width=117&height=57" alt="" title="" onload="registerImageObject(this, this.width, this.height, 26, 57);" style="width: 14%;">
</div>
<a buttonid="501" id="X22Border" href="javascript:tpzDrillTable('var/L.item.1', 'Employee Lifecycle Services', '501','',true)" title="Employee Lifecycle Services" tabindex="" content="Employee Lifecycle Services">
<img class="HoverImage" id="X22" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Employee Lifecycle Services" title="Employee Lifecycle Services" enabled="1">
Employee Lifecycle Services
</a>
<input type="hidden" id="var/L.item.1" name="var/L.item.1">
<span id="X23" type="label">
Contains lifecycle services available to employees and managers, including New Employee requests, Personal Information Change, and Employment Status Change, …
</span>
<div id="X24">
<img src="servlet/image?application=joinsvcDisplay&topic=Personal+Productivity+Services&type=img&key=GYa3ZmEl4rbIfTpSb%2FqqFA&width=117&height=57" alt="" title="" onload="registerImageObject(this, this.width, this.height, 26, 57);" style="width: 14%;">
</div>
<a buttonid="502" id="X25Border" href="javascript:tpzDrillTable('var/L.item.2', 'Personal Productivity Services', '502','',true)" title="Personal Productivity Services" tabindex="" content="Personal Productivity Services">
<img class="HoverImage" id="X25" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Personal Productivity Services" title="Personal Productivity Services" enabled="1">
Personal Productivity Services
</a>
<input type="hidden" id="var/L.item.2" name="var/L.item.2">
<span id="X26" type="label">
Contains common employee services such as telecommunications, collaboration support, accounts, network access, software, hardware bundles …
</span>
<a buttonid="503" id="X28Border" href="javascript:void(0);" title="Item 3" tabindex="" content="Item 3" style="visibility: hidden;">
<img class="HoverImage" id="X28" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 3" title="Item 3" enabled="0">
Item 3
</a>
<input type="hidden" id="var/L.item.3" name="var/L.item.3">
<span id="X29" type="label" style="visibility: hidden;">
Desc3
</span>
<a buttonid="504" id="X31Border" href="javascript:void(0);" title="Item 4" tabindex="" content="Item 4" style="visibility: hidden;">
<img class="HoverImage" id="X31" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 4" title="Item 4" enabled="0">
Item 4
</a>
<input type="hidden" id="var/L.item.4" name="var/L.item.4">
<span id="X32" type="label" style="visibility: hidden;">
Desc4
</span>
<a buttonid="505" id="X34Border" href="javascript:void(0);" title="Item 5" tabindex="" content="Item 5" style="visibility: hidden;">
<img class="HoverImage" id="X34" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 5" title="Item 5" enabled="0">
Item 5
</a>
<input type="hidden" id="var/L.item.5" name="var/L.item.5">
<span id="X35" type="label" style="visibility: hidden;">
Desc5
</span>
<span id="X38" type="label">
Items 1-2 of 2
</span>
</fieldset>
</div>
</body>
</html>
а когда пробую их же удалить то сбой почему то:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function RemoveEl(ContainerElementId, RemoveElementType)
{
var tmpdoc = document.getElementById(ContainerElementId);
var oc=tmpdoc.getElementsByTagName(RemoveElementType)
alert('udalim: ' + oc.length)
for (var i=0; i<oc.length; i++)
{
//alert(oc[i]);
oc[i].parentNode ? oc[i].parentNode.removeChild(oc[i]) : oc[i];
}
};
</script>
</head>
<body>
<button onclick="RemoveEl('ServiceCatalog', 'img');">Run</button>
<div id="ServiceCatalog">
<fieldset id="X15" widgettype="group" class="groupBox">
<legend id="X15Legend">
<span class="caption" id="X15Caption">
Service Catalog
</span>
</legend>
<div id="X21">
<img src="servlet/image?application=joinsvcDisplay&topic=Employee+Lifecycle+Services&type=img&key=j3gzV0NsEk6fQw6ZjH2%2Fdg&width=117&height=57" alt="" title="" onload="registerImageObject(this, this.width, this.height, 26, 57);" style="width: 14%;">
</div>
<a buttonid="501" id="X22Border" href="javascript:tpzDrillTable('var/L.item.1', 'Employee Lifecycle Services', '501','',true)" title="Employee Lifecycle Services" tabindex="" content="Employee Lifecycle Services">
<img class="HoverImage" id="X22" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Employee Lifecycle Services" title="Employee Lifecycle Services" enabled="1">
Employee Lifecycle Services
</a>
<input type="hidden" id="var/L.item.1" name="var/L.item.1">
<span id="X23" type="label">
Contains lifecycle services available to employees and managers, including New Employee requests, Personal Information Change, and Employment Status Change, …
</span>
<div id="X24">
<img src="servlet/image?application=joinsvcDisplay&topic=Personal+Productivity+Services&type=img&key=GYa3ZmEl4rbIfTpSb%2FqqFA&width=117&height=57" alt="" title="" onload="registerImageObject(this, this.width, this.height, 26, 57);" style="width: 14%;">
</div>
<a buttonid="502" id="X25Border" href="javascript:tpzDrillTable('var/L.item.2', 'Personal Productivity Services', '502','',true)" title="Personal Productivity Services" tabindex="" content="Personal Productivity Services">
<img class="HoverImage" id="X25" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Personal Productivity Services" title="Personal Productivity Services" enabled="1">
Personal Productivity Services
</a>
<input type="hidden" id="var/L.item.2" name="var/L.item.2">
<span id="X26" type="label">
Contains common employee services such as telecommunications, collaboration support, accounts, network access, software, hardware bundles …
</span>
<a buttonid="503" id="X28Border" href="javascript:void(0);" title="Item 3" tabindex="" content="Item 3" style="visibility: hidden;">
<img class="HoverImage" id="X28" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 3" title="Item 3" enabled="0">
Item 3
</a>
<input type="hidden" id="var/L.item.3" name="var/L.item.3">
<span id="X29" type="label" style="visibility: hidden;">
Desc3
</span>
<a buttonid="504" id="X31Border" href="javascript:void(0);" title="Item 4" tabindex="" content="Item 4" style="visibility: hidden;">
<img class="HoverImage" id="X31" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 4" title="Item 4" enabled="0">
Item 4
</a>
<input type="hidden" id="var/L.item.4" name="var/L.item.4">
<span id="X32" type="label" style="visibility: hidden;">
Desc4
</span>
<a buttonid="505" id="X34Border" href="javascript:void(0);" title="Item 5" tabindex="" content="Item 5" style="visibility: hidden;">
<img class="HoverImage" id="X34" onmouseover="if(top.is_ie)this.className='HoverImageHover'" onmouseout="if(top.is_ie)this.className='HoverImage'" widgettype="linklabel" align="left" src="images/obj16/ind_green.gif" alt="Item 5" title="Item 5" enabled="0">
Item 5
</a>
<input type="hidden" id="var/L.item.5" name="var/L.item.5">
<span id="X35" type="label" style="visibility: hidden;">
Desc5
</span>
<span id="X38" type="label">
Items 1-2 of 2
</span>
</fieldset>
</div>
</body>
</html>