views:

44

answers:

2

Hi,

I am facing an issue because of removeChild method in javascript.

I am using below code to remove a div tag.

this.parent.parent.removeChild(this.parent).

that code is working pretty fine in FF but it give me error in IE7/8.

" Error: Object doesn't support this property or method ".

is removeChild method is not supported in IE7/8 or is there any other alternate of this method?

Regards,
Mahendra Athneria
Mumbai,Maharashtra,India

+1  A: 

It should be parentNode not parent

meder
Hi Meder, yes it is parent only. please check my code which i have added in my question. but i am facing the issue with parent too.
Mahendra Athneria
Please post a full demo to jsfiddle.net
meder
i dont know how to use it.
Mahendra Athneria
Put HTML in the HTML box. CSS in CSS, and so forth. Use absolute urls for media.
meder
it is not working there. i had put html,css and js code on the proper place and run it. but when i clicked on the button it give me error that function is not defined.
Mahendra Athneria
A: 

Hi All,

thanks for your precious time and reply. special thanks to Meder.

Finally i found the solution.

Here is my solution and analysis.

actually in my code i was using this.parent.parent.removeChild(this.parent) to delete the child. this.parent return [object window] and [object window] does not support the removeChild property. to use removeChild method we need the Element and to get the element i made some change in my code.

1st - change the method signature.
function removeCriteria(thisObj) {.....}

2nd -only for IE
thisObj.srcElement.parentElement.parentElement.removeChild(thisObj.srcElement.parentElement);
this solution works for me and hope my analysis is right :-)

For @Meder & other seniors - correct me if i am wrong.

Regards,
Mahendra
Mumbai,Maharashtra,India

Mahendra Athneria