0

I need to remove or modify elements created by OpenLayers library. If I delete it, I cannot see it in the console.debug anymore if displayed by id, but they are still present in the browser.

console.debug($("#OpenLayers_Geometry_Point_85"));

Perfect, I can see the output in the console. When I hover over it, the element in the browser gets highlighted.

$("#OpenLayers_Geometry_Point_85").remove();

An attempt to remove the element, it behaves essentially in the same way as:

var img = document.getElementById("OpenLayers_Geometry_Point_85");
img.parentNode.removeChild(img);
console.debug($("#OpenLayers_Geometry_Point_85"));

Now the second output in console.debug is different, it is empty, so it has been deleted. However, in the browser I can still see it. Hovering over the first output does not highlight anything anymore. When inspecting the element, it shows me the code that has been removed! Or is it still there?

Please, note, that I have checked for duplicates. I am performing the operation after the document has been fully loaded. The element is of SVG type, but this should not matter or does it?


Question: How can I remove the element from the browser completely?

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
Dávid Natingga
  • 839
  • 3
  • 13
  • 30
  • 4
    Do you have a simple test we can all work with? Maybe a http://jsfiddle.net? – TheZ Aug 13 '12 at 18:45
  • 3
    make a jsfiddle with your markup and describe what you expect the result to be. – Visionary Software Solutions Aug 13 '12 at 18:46
  • What is the parentNode? is it the SVG element or some kind of conatianing element used as a wrapper around that image? if its the latter then i may be the event handler is attached to parentNode not the actual image. – prodigitalson Aug 13 '12 at 18:48
  • The parentNode of the element is the following: `...... ` so it is a wrapper. How can I find if it is an event handler? – Dávid Natingga Aug 13 '12 at 18:52
  • Actually, g element is just for grouping SVG shapes: http://tutorials.jenkov.com/svg/g-element.html – Dávid Natingga Aug 13 '12 at 18:54
  • If I understand correctly, JsFiddle is just for displaying the code. Unfortunately, the code I am working with is complex so it is hard to extract only the relevant part. Moreover, I cannot display the original version as it is protected and is an ownership of a company. – Dávid Natingga Aug 13 '12 at 18:59
  • But in principle, I am using an unmodified OpenLayers.js library, then performing certain manipulations that do not affect or intercede in any way with OpenLayers rendered elements. And finally I try to change or delete the elements from the OpenLayers layers but it does not seem to work. – Dávid Natingga Aug 13 '12 at 19:02
  • I think I found the problem: OpenLayers.js library recreates all the elements with the identical content (even ids) upon zooming in and zooming out or moving. It does not use the same elements. So even when I deleted the element, it was created again. So when I wanted to see if it was still there, a different one identical to the old one was. – Dávid Natingga Aug 13 '12 at 21:22

0 Answers0