Javascript 在每个循环中使用setAttributeNS

Javascript 在每个循环中使用setAttributeNS,javascript,jquery,svg,Javascript,Jquery,Svg,我需要更改页面上所有svg的url。我有以下代码,但在尝试使用setAttributeNS时出错 jQuery("[*|href*='icons.svg']:not([href])").each(function () { hashedIconUrl = jQuery(this).attr('xlink:href').replace('icons.svg', hashedIcon); console.log(hashedIconUrl); jQuery(this).setAttr

我需要更改页面上所有svg的url。我有以下代码,但在尝试使用setAttributeNS时出错

jQuery("[*|href*='icons.svg']:not([href])").each(function () {

  hashedIconUrl = jQuery(this).attr('xlink:href').replace('icons.svg', hashedIcon);
  console.log(hashedIconUrl);

  jQuery(this).setAttributeNS('http://www.w3.org/1999/xlink', 'href', hashedIconUrl);
});

您需要将jQuery对象转换为本机DOM对象以调用setAttributeNS。通常的方法是通过[0]

jQuery("[*|href*='icons.svg']:not([href])").each(function () {

  hashedIconUrl = jQuery(this).attr('xlink:href').replace('icons.svg', hashedIcon);
  console.log(hashedIconUrl);

  jQuery(this)[0].setAttributeNS('http://www.w3.org/1999/xlink', 'href', hashedIconUrl);
});

但是当我尝试使用setAttributeNS时出现错误
什么错误?未捕获的TypeError:n(…)。setAttributeNS不是一个函数