Find, Create and Manage SVG Element

Just list some frequence usage
------------------------------
tspan:
  • Get by type: var tspans = document.getElementsByTagName("tspan");
  • Get text: var text= tspan.firstChild.nodeValue;
  • Create text:
  • var txt=document.createElementNS('http://www.w3.org/2000/svg','text'); 
    var tspan=document.createElementNS('http://www.w3.org/2000/svg','tspan'); 
    var tnode = document.createTextNode("This is the text");
    tspan.appendChild(tnode);
    txt.appendChild(tspan);
  • onclick: tspan.setAttribute("onclick", "alert(this.id)");
  • // TODO: this code does not work in IE.

    xlink:href:
  • Set href attr:
  • var bg = document.getElementById("ImageId");
    var svgNS="http://www.w3.org/2000/svg";
    var xlinkNS="http://www.w3.org/1999/xlink";
    bg.setAttributeNS(xlinkNS,"href","I.png");


    你可能感兴趣的:(IE)