Change color of a svg Under Object Tag

PHOTO EMBED

Tue Jun 04 2024 11:36:21 GMT+0000 (Coordinated Universal Time)

Saved by @riyadhbin

<script>
// Get all object elements
const objectElements = document.querySelectorAll('.relation-block object');

// Iterate over each object element
objectElements.forEach(objectElement => {
    // Listen for the load event on each object element
    objectElement.addEventListener('load', function() {
        // Get the SVG document inside the object element
        const svgDoc = objectElement.contentDocument;

        // Check if the SVG document is accessible
        if (svgDoc) {
            // Get all path elements inside the SVG document
            const pathElements = svgDoc.querySelectorAll('path');

            // Change the fill color of each path element to red
            pathElements.forEach(path => {
                path.style.fill = '#0c71c3';
            });
        } else {
            console.error('SVG document not accessible');
        }
    });
});

</script>
content_copyCOPY