getElementsByTagName question

getElementsByTagName question

am 13.04.2008 17:43:01 von rodchar

hey all,
is there a way to delete or remove and item from the results of
getElementsByTagName?

thanks,
rodchar

Re: getElementsByTagName question

am 13.04.2008 19:59:06 von Anthony Jones

"rodchar" wrote in message
news:382C4C64-3F28-469C-874B-DB9B54785B1A@microsoft.com...
> hey all,
> is there a way to delete or remove and item from the results of
> getElementsByTagName?
>


Its not entirely clear what you actually want to do.

If you mean you want to take the list of items returned by
getElementsByTagName and remove an item from that list then:-

no you can't do that directly. You can copy the list into an array skipping
any that do not conform to come criteria:-

function filterNodeSet(nodeSet, callback)
{
var resultSet = new Array()
for (var i = 0, length = list.length; i < length; i++)
if (callback(nodeSet[i])) resultSet.push(nodeSet[i])
}


var newSet = filterNodeSet(oldSet, function(node) {
return
})


If you mean can you delete from the DOM a node found via
getElementsByTagName then yes:-

nodeSet[i].parentNode.removeChild(nodeSet[i])



--
Anthony Jones - MVP ASP/ASP.NET

Re: getElementsByTagName question

am 14.04.2008 04:33:00 von rodchar

thank you it was the 1st one but thank you for covering both,
rod.

"Anthony Jones" wrote:

> "rodchar" wrote in message
> news:382C4C64-3F28-469C-874B-DB9B54785B1A@microsoft.com...
> > hey all,
> > is there a way to delete or remove and item from the results of
> > getElementsByTagName?
> >
>
>
> Its not entirely clear what you actually want to do.
>
> If you mean you want to take the list of items returned by
> getElementsByTagName and remove an item from that list then:-
>
> no you can't do that directly. You can copy the list into an array skipping
> any that do not conform to come criteria:-
>
> function filterNodeSet(nodeSet, callback)
> {
> var resultSet = new Array()
> for (var i = 0, length = list.length; i < length; i++)
> if (callback(nodeSet[i])) resultSet.push(nodeSet[i])
> }
>
>
> var newSet = filterNodeSet(oldSet, function(node) {
> return
> })
>
>
> If you mean can you delete from the DOM a node found via
> getElementsByTagName then yes:-
>
> nodeSet[i].parentNode.removeChild(nodeSet[i])
>
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>
>