the code was not working for elements which did not contain images,scripts,links or iframes. fixed that. also changed temp wrapper from p tag to div tag