Question

J'ai le code HTML suivant

<div>
    <a id="cover"></a>
    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 510 680">
    <rect x="0" y="0" fill="#000007" width="510" height="680"/>
    <image width="510" height="680" xlink:href="../images/MSRCover.png" transform="translate(0 0)" />
    </svg>
</div>

J'essaie de changer le chemin de l'image avec jQuery et l'image devient noir.

$ = cheerio.load(data);
$('image').each(function()
{
    var $img    = $(this);
    $(this).attr('xlink:href','My PATH').html();
});

J'utilise node.js et le module cheerio.

merci

Était-ce utile?

La solution

La méthode jQuery .attr ne comprend pas les espaces de noms.Utilisez la normale DOM Setattributs à la place par ex.

$(this)[0].setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "My PATH");

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top