getElementsByTagName question

R

rodchar

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

thanks,
rodchar
 
A

Anthony Jones

rodchar said:
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)) resultSet.push(nodeSet)
}


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.parentNode.removeChild(nodeSet)
 
R

rodchar

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

Anthony Jones said:
rodchar said:
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)) resultSet.push(nodeSet)
}


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.parentNode.removeChild(nodeSet)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top