farroar
asked on
Delete a div tag from page
How do I remove a div tag completely (both <div> and </div> and all content inside)?
I have a form input box that allows you to enter in a name. Once you click 'add' it displays that name on the page with a remove link next to it inside of a DIV tag with an id that increments with each name added. I need to use that id to remove the entire tag and contents.
In the code below I am using a td tag with the id of 'names' as my container for the names added. Want to delete Frank Rizzo and the DIVs surrounding it.
Thanks!
I have a form input box that allows you to enter in a name. Once you click 'add' it displays that name on the page with a remove link next to it inside of a DIV tag with an id that increments with each name added. I need to use that id to remove the entire tag and contents.
In the code below I am using a td tag with the id of 'names' as my container for the names added. Want to delete Frank Rizzo and the DIVs surrounding it.
Thanks!
<table>
<tr>
<td width="70">People:</td>
<td>
<input type="text" id="personName" />
<a href="#" onclick="addName(document.getElementById('personName').value);">add</a>
</td>
</tr>
<tr>
<td colspan="2" id="names">
<div id="1">Frank Rizzo <a href="#" onclick="removeName(document.getElementById('1'))">remove</a></div
</td>
</tr>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This answer is concise and simple. Both would have worked but this one jives with my current code better. Thanks!
no need to looking for <div> tag by id, and able to remove <div> tag even <a> tag is included by several tags (span, p)
test on ie6,ff3,opera, safari
;)
Open in new window