skip to Main Content

Adding SVGs in HTML Elements using Javascript

I have an SVG that I want to add in every div displayed on the screen using a for loop. SVG: <div class='cart'> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve"> <defs> </defs> <g style="stroke: none; stroke-width:…

VIEW QUESTION

Javascript in my SVG files do not run when wrapped in CDATA tags – CSS

I have an SVG file in the form of the following: <svg id="test" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" viewBox="0 0 1435 1084"> <style type="text/css"> svg{background:red} </style> <script type="text/javascript">//<![CDATA[ const x=1; const y=1; if (x===y){ document.getElementById('test').append('<style type="text/css">svg{background:blue}</style>'); }else{} //]]></script> </svg> What I…

VIEW QUESTION
Back To Top
Search