Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can store a reference to a SVG object created in a simple javascript variable. So, when you create a shape, you can do this:</p> <pre><code>myRect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); </code></pre> <p>Now you have the reference to a shape of the SVG object. But if you want to make them interactive, you just have to add attributes to the object like this.</p> <pre><code>myRect.setAttribute("onclick", "jsFunc()"); </code></pre> <p>where jsFunc() is a previously defined function. Also, to make things easier, you can set the events this way:</p> <pre><code>myRect.onclick = function(){jsFunct(this, otherArg);} </code></pre> <p>Now You can not only have the reference to the variable, but to pass the variable itself to the function jsFunc using such alternative through the use of the pointer this.</p> <p>If you have to create a lot of Rectangles, you can store them all in a single Array, so you are able to access each element using an index:</p> <pre><code>myRect = new Array(); for(i = 1; i &lt;= numMakes; i = i + 1){ myRect[i] = document.createElementNS("http://www.w3.org/2000/svg", "rect"); } </code></pre> <p>Remember, to get a property or attribute of your object, you can use the function getAttribute, like this:</p> <pre><code>fillColor = myRect.getAttribute("fill"); x = myRect.getAttribute("x"); </code></pre> <p>and so on.</p> <p>You could create a new variable type object, and establish that one member is the svg shape, and the rest of members are your customized data fields. </p> <pre><code>var myRect = new Object(); myRect.shape = document.createElementNS("http://www.w3.org/2000/svg", "rect"); myRect.customField = myValue; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload