Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get xlink:href using javascript (in browser)

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.)

like image 276
user984003 Avatar asked Oct 28 '25 12:10

user984003


1 Answers

<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');
like image 159
Filo Avatar answered Oct 30 '25 02:10

Filo