Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body onload="main()">
  <h2>SVG Integram al DOM</h2>
  <p onclick="afegirNodeAleatori()">pitja per crear nou node</p>
  <p id="info"></p>
  <div id="svg54583"></div>
</body>
<script>
//https://www.d3-graph-gallery.com/graph/shape.html
var svg1 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var i=0;

function creaEscenari(){
      // set width and height
      svg1.setAttribute("width", "700");
      svg1.setAttribute("height", "350");
      //feim un fons de imatge.
      var rec1 = document.createElementNS("http://www.w3.org/2000/svg", "rect");
      //Assignam els atributs
      rec1.setAttribute("height", "350");
      rec1.setAttribute("width", "700");
      rec1.setAttribute("style", "fill:rgb(80,80,120);stroke-width:3;stroke:rgb(0,0,0)");
      //Afegim al SVG1
      svg1.appendChild(rec1);
      // attach container to document
      document.getElementById("svg54583").appendChild(svg1);
}

function simple2(t){
  var x= t.getAttribute("cx");
  var y= t.getAttribute("cy");
  document.getElementById("info").innerHTML="element: " + t.id +", posició: " + x + ", " +y;

}

function afegirNode(){
  var cir1 = document. createElementNS("http://www.w3.org/2000/svg", "circle");
  cir1.setAttribute("id","patata");
  cir1.setAttribute("cx", "100");
  cir1.setAttribute("cy", "100");
  cir1.setAttribute("r", "30");
  cir1.setAttribute("fill", "blue");
  svg1.appendChild(cir1);
  document.getElementById("patata").addEventListener("click",simple);

}

function afegirNodeAleatori(){
  var cir1 = document. createElementNS("http://www.w3.org/2000/svg", "circle");
  cir1.setAttribute("id","node"+i);

  cir1.setAttribute("cx", Math.floor(Math.random() * 700));
  cir1.setAttribute("cy", Math.floor(Math.random() * 350));
  cir1.setAttribute("r", "30");
  cir1.setAttribute("fill", "blue");
  svg1.appendChild(cir1);
  document.getElementById("node"+i).addEventListener("click",function(){simple2(this)});
  i++;
}

function main(){
  //escenari = new Escena("get");
  creaEscenari();
  afegirNode();
// create svg element:


  // create svg element:


}
</script>

</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console