Conflicting identifiers in two different SVG files included in the same HTML document

So, I have one .svg file with several pre-created gradient effects:

<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="1052.4" width="744.09" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 670 680" style="width: 100%; height: 100%;">

<defs>
    <radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
        <stop offset="0%" style="stop-color: #a0a0a0;" />
        <stop offset="100%" style="stop-color: #a0a0a0;" />
    </radialGradient>
</defs>
 <g>
  <path id="path1" d="m124 263.35c6.4216-12.385 18.974-0.67157 0.72621z" fill="url(#grad1)">
  </path>
</g>
</svg>

This is a simplified version of my svg file. It is a map in which each state is an element of the path. Each state also has a radial gradient sign associated with it. The problem I am facing is that I add this SVG file twice to my HTML document and I change the radial gradient tags to svg to change the color of the state on each map separately.

The maps also have some interactivity, I use the following code to load svg and add events that bring the state forward (so we can see its progress) when the user hovers the mouse over the map:

$divSVG.load("map.svg", function() {
    $svg= $(this).find("svg");
    $svg.find("path").each(function() { 
        $(this).bind("mouseenter", function() {
                var $path= $(this);
            var $parent= $path.parent();
            //its necessary to detach and reattach the element so it comes to the front
            //of the image (there is no z-index in SVG)
            $path.detach();
            $parent.append($path);
            $path
                .css("stroke", "#FF0000")
                .css("stroke-width", "5px");
        });
        $(this).bind("mouseleave", function() {
            $(this)
                .css("stroke", "#FFFFFF")
                .css("stroke-width", "3px");
        });
    }
});

, , .

: , , , . , , , .

, , , , , , HTML, , SVG.

, , ? SVG . javascript. ?

+5

All Articles