- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>SVG element test</title>
window.onload = function()
SVG element test:
<svg id="svg_elem" xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:600px; height:400px;"/>
On loading, offsetParent for svg_elem is reported as undefined. I guess it's because svg is using a different namespace but the original problem really is, how to get a relative offset in an svg element, based on mouse event. I thought to do it using the absolute cursor position which comes from mouse event and offsetParent, offsetTop etc. (as described here: http://www.quirksmode.org/js/findpos.html ) but they don't work at all for an <svg> which is defined within xhtml. So is there another way to do it?