0
<a class="but-arrow" href="">
    <img class="svg" src="img/icons/arrow.svg" alt="" />
</a>  
function svg() {
    $('img[src$=".svg"]').each(function () {
        var $img = $(this)
        var imgURL = $img.attr('src')
        var attributes = $img.prop('attributes')
        if ($img.hasClass('svg')) {
            $.get(
                imgURL,
                function (data) {
                    var $svg = jQuery(data).find('svg')
                    $svg = $svg.removeAttr('xmlns:a')
                    $.each(attributes, function () {
                        $svg.attr(this.name, this.value)
                    })
                    $img.removeClass('svg').replaceWith($svg)
                },
                'xml'
            )
        }
    })
}
svg()
<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.07812 13.9866L5.25812 15.1666L11.9248 8.49998L5.25812 1.83331L4.07812 3.01331L9.56479 8.49998L4.07812 13.9866Z" fill="#868686"/>
</svg>

HTML in arrow.svg

What does the colon and :a mean here in $svg.removeAttr('xmlns:a')? Represents a namespace?

I know that the jQuery event has a dot "." to represent the namespace, but I have never seen a colon.

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
Felix
  • 11
  • 2
  • In JavaScript/jQuery? Nothing, it's just another character in a string. Otherwise see: – jonrsharpe Jul 11 '23 at 07:43
  • Also what is the purpose of removing the namespace? The code will not work since there is no :a in the namespace in the provided SVG – mplungjan Jul 11 '23 at 07:44
  • @mplungjan This is someone else's code, I just want to understand why he uses it like this? – Felix Jul 11 '23 at 08:25
  • @jonrsharpe The point of my question isn't XML namespaces, I'm just saying it's like. – Felix Jul 11 '23 at 08:27

0 Answers0