简体   繁体   中英

Append SVG element to an existing SVG element using JS

I am trying to append SVG element circle to an existing SVG element , i want to circle to sit on top of map ie overlay but i am unable to do it properly , i have created JSfiddle for it .Please let me know how to achieve this.

MY code is here

How to append at exact co ordinate i am using below code

document.getElementById('us').appendChild(c1);

You should remove onmouseover attribute from html and bind mouseover event in javascript code, something like this pseudocode:

var item = document.getElementById('id');
item.addEventListener('mouseover', function() {
    var x = getXPosition();
    var y = getYPosition();
    circleElement.setAttribute('cx', x);
    circleElement.setAttribute('cy', y);
}, false);

You should also show/hide element when needed with css classes, inline style or any other method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM