I need to find an element, which could be created dynamically and part of DOM, and change few of its attributes. I am trying it on svg elements, but your expertise in Javascript /Jquery would help me.
<svg id="cvs" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" >
<rect uid="id1" class="cont" x="0" y="0" width="200" height="200" />
</svg>
At run time, I add few more rect elements like
var el = document.createElementNS(svgNS,'rect');
//set the attribues including uid //say id2, id3 etc
svg.appendChild(el);
Now, I need to write an update method, where it matches the rect elelement based on uid, sets all the attribues.
updateRect = function(properties){
$('rect[uid="' + properties.uid + '"]') {
for (var p in properties) {
this.setAttribute(p,prop[p]);
}
}
};
It is more of a pseudo code to show my intentions. I am not sure whether it would find the dynamically created elements as well. Is there a better logic? I don't have to use jQuery, but any JS sol would be highly appreciated.
Edit 1: The selector may be working, but I am bit lost in how can I chain the operation on the selected object.
something like,
var el = $('rect[uid="' + properties.uid + '"]')
if el.exist() {
//do the operation
}
or a better way??? thanks... thanks, bsr.