getElementsByTagName question
hey all,
is there a way to delete or remove and item from the results of
getElementsByTagName?
thanks,
rodchar
Re: getElementsByTagName question
"rodchar" <rodchar [at] discussions.microsoft.com> wrote in message
news:382C4C64-3F28-469C-874B-DB9B54785B1A [at] 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 <boolean expression using node here>
})
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
thank you it was the 1st one but thank you for covering both,
rod.
"Anthony Jones" wrote:
> "rodchar" <rodchar [at] discussions.microsoft.com> wrote in message
> news:382C4C64-3F28-469C-874B-DB9B54785B1A [at] 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 <boolean expression using node here>
> })
>
>
> 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
>
>
>