My goal is to change a fill
attribute of a <path>
element, upon the loading of a page.
This is the path element:
<path xmlns="http://www.w3.org/2000/svg"
style="fill:#ff0000;stroke:#000000;stroke-width:0.26458332px;stroke-
linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
d="M 71.895501,10.754349 94.88068,-28.80154 112.52047,12.892505 Z"
id="element"/>
The path element is located inside of a map.svg file, I load the SVG in my html file, with a <object>
element, since I've seen this answer, I decided to use <object>
element.
index.html
This is the HTML file:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Dental Ordination</title>
<script src="svg.min.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<object type="image/svg+xml" data="map.svg"/>
<script src="main.js"></script>
</body>
</html>
main.js
And this is my JavaScript file:
$(document).ready(function () {
$("#element").attr("fill", "blue");
});
When executed, paths fill doesn't change. So I tried to debug it, I've put console.log($("#element").attr("fill"));
, to see what it returns, and it returned undefined
.