Pregunta

Tengo el siguiente código HTML

<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>

Estoy tratando de cambiar la ruta de la imagen con jQuery y la imagen se vuelve negra.

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

Estoy usando nodo.js y el module cheerio.

gracias

¿Fue útil?

Solución

El método jQuery .attr no entiende los espacios de nombres.Use Normal Dom SetAtTributens en su lugar, por ejemplo,.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top