Access SVG Elements Through Javascript

This is the next question asked earlier: How to access SVG elements using Javascript However, the solution does not seem to work for me. I am testing the latest version of Chrome. I have a map of the USA as an SVG file that I downloaded to my machine and made some changes to the xml code.

I have svg embedded using an object tag and assigned the identifier "USAsvg", and first I start the steps for the child. For the onclick button, I execute the following code without success. Here "CA" is the state declared using the path tag in the svg file.

var a = document.getElementById('USAsvg');
var svgDoc = a.contentDocument; 
var delta = svgDoc.getElementById('CA');

alert(delta.value);
+3
source share
1 answer

, SVG DOM , , html node, html() jQuery , ().

$('.your_div_for_svg').load('svg/file.svg', function(){
      $('#some_textnode_w_id_within_svg').text('Hello word');
});
+1

Source: https://habr.com/ru/post/1787088/


All Articles