...

View Full Version : removing a div vased on (id) from a split() match....



arron3
09-06-2008, 01:39 PM
<script Language="JavaScript">
function removeElement(ele){
pieces = ele.split("_");
var ele = pieces[0]; ele.parentNode.removeChild(ele);
}
</script>

<div id="1">Industrial Goods <input type="button" value="Delete" onClick="removeElement(1_1)"> <br> </div>


So, the div ID is "1" and the variable passed is 1_1, I want to split 1_2 ( using the underscore to split it) > then use the splitpiece[0] to identify the div="1" tag and delete it.....

But it isnt working for some reason...

Thanks!

Philip M
09-07-2008, 09:37 AM
1_1 is a string and must be enclosed in quotes. '1_1'

<script type = "text/javascript">
function removeElement(ele){
pieces = ele.split("_");
var ele = pieces[0];
ele.parentNode.removeChild(ele);
}
</script>

<div id="1">Industrial Goods <input type="button" value="Delete" onClick="removeElement('1_1')"> <br> </div>



I may not be perfect, but parts of me are excellent.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum