[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

remove child node

Posted on 2009-04-21
6
Medium Priority
?
1,064 Views
Last Modified: 2013-11-19
When I execute this script I get "No such interface supported".  It's supposed to remove the <span>  What am I doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
 
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<script type="text/javascript">
	window.onload = function() {
	var elem =  document.getElementById("TD1");
	var spanElem=elem.getElementsByTagName("span");
	elem.removeChild(spanElem);
}
</script>
</head>
<body>
<Table>
<tr><td ID="TD1"><span>This is the span</span>Other text</td></tr></table>
</body>
</html>

Open in new window

0
Comment
Question by:PhotoCompManager
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:mudbuggle
ID: 24197430
try
elem.removeChild(elem.firstChild);
0
 

Author Comment

by:PhotoCompManager
ID: 24197557
That works, but don't know the child position in the real app. I suppose I have to loop through the children looking for the span
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24197627
Or, given some parent node, you can use:

parentNode.getElementsByTagName( 'SPAN' )

which will return a (possibly empty) collection of all SPAN elements that are beneath the specified parentNode element...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 24197681
for example
<html>
<body>
 
<table border='1'>
 <tr>
   <td ID="TD1">
     <span>This is the span</span>Other text
   </td>
 </tr>
</table>
 
<script type="text/javascript">
 
var td = document.getElementById( 'TD1' )
if ( td ) {
  var spans = td.getElementsByTagName( 'SPAN' )
  alert( '# spans: ' + spans.length )
  for ( var i = 0; i < spans.length; i++ ) {
    var span   = spans[ i ]
    var parent = span.parentNode
    parent.removeChild( span )
  }
} else {
  alert( 'Specified element not found: id="TD1".' )
}
 
 
</script>
 
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:PhotoCompManager
ID: 31572929
Many thanks
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24200117
You are welcome.  Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to implement server side field validation and display customized error messages to the client.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question