JavaScript: Add Nodes to Current Use Element
To add a node to the current 'useElement', you can use the 'appendChild' method. Here's an example of how you can do it:
for (let i = 0; i < useElements.length; i++) {
const useElement = useElements[i];
const xlinkHref = useElement.getAttribute('xlink:href');
const newxlinkHref = xlinkHref.replace('#', '');
// Create a new node
const newNode = document.createElement('circle');
newNode.setAttribute('cx', '50');
newNode.setAttribute('cy', '50');
newNode.setAttribute('r', '20');
newNode.setAttribute('fill', 'red');
// Append the new node to the useElement
useElement.appendChild(newNode);
}
In this example, a new <circle> element is created and appended to each 'useElement'. You can customize the attributes of the new node according to your needs.
原文地址: https://www.cveoy.top/t/topic/fTM3 著作权归作者所有。请勿转载和采集!