get xlink:href using javascript (in browser)

dom, html, javascript

Solution

<image xlink:href="https://abc" id="my_ele">

and

ele = document.getElementById("my_ele")
var url = ele.getAttributeNS('http://www.w3.org/1999/xlink', 'href');

Problem

I have an element (in html) ``` <image xlink:url="https://abc" id="my_ele"> ``` I do ``` ele = document.getElementById("my_ele") // Now want to get https://abc ``` This answer here Getting 'xlink:href' attribute of the SVG <image> element dynamically using JS in HTML DOM says: ``` getAttributeNS('http://www.w3.org/1999/xlink', 'href'); ``` But I'm not really sure what that translates to in my example. (btw, Google docs displays images like this, at least in Chrome. Don't know why they don't use a proper IMG tag.)

Original source

Related problems