Zur Startseite - about-svg.de
  Scripting
  DOM
  getDocument
  getElementById
  get...sByTagName
  getStyle
  setAttribute
  createElement
  get...TextLenght
   

 

 

 

createElement

 

createElement(elementName)

Diese Funktion erzeugt ein neues Element.

 

Beispiel:

 

 

 


Quellcode:
 
   
 

<script type="text/javascript">
<![CDATA[

function neu(evt) {
var doku = evt.target();
var owner = doku.ownerDocument();
var elem = owner.createElement('rect');
elem.setAttribute('x',50);
elem.setAttribute('y',80);
elem.setAttribute('width',100);
elem.setAttribute('height',70);
elem.setAttribute('rx',5);
elem.setAttribute('ry',5);
elem.setAttribute('fill','#990000');
elem.setAttribute('stroke','white');
var eltern = doku.parentNode();
eltern.appendChild(elem);
}

]]>
</script>

<circle cx="230" cy="100" r="10" fill="#990000" opacity="0.5" onclick="neu(evt)" cursor="pointer">
<set attributeName="opacity" attributeType="CSS" to="1.0" begin="mouseover"/>
<set attributeName="stroke" attributeType="CSS" to="#fff" begin="mouseover"/>
<set attributeName="opacity" attributeType="CSS" to="0.5" begin="mouseout"/>
<set attributeName="stroke" attributeType="CSS" to="none" begin="mouseout"/>
</circle>

<text x="250" y="105" fill="white" pointer-events="none">
<tspan>neues Rechteck</tspan>
</text>

 

  nach oben 

 
 
  Zum Leipzig-Entertainer (SVG)  
     
  Zum Campusplan (SVG)  
     
  Zum SVG-Tutorial (SVG)  
     
  Zum Wankelmotor (SVG)