getElementsByTagName question

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

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

thanks,
rodchar
 
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)
 
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

Back
Top