Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing attributes of a graphic (line)

ANSWERED

I'm struggling to understand how I can change the attributes of a line. I've got a very simple test program.

index.gui:
<svg class="background">
<line id="testline" x1="10" y1="10" x2="100" y2="100" fill="black" stroke-width="4"/>
</svg>


index.js:

import document from "document";

let testline = document.getElementById("testline");
var count = 0;

document.onkeypress = function(e)
{
  if(e.key=="up")
  {
    count++;
    console.log(count);
    switch(count)
    {
      case 1:
        testline.style.x1="20";
        break;
      case 2:
        testline.style.x1="100";
        count=0;
        break;
    }
  }
}

 

I'd just like to get the line to move, to give it different co-ordinates, this is the basis of an app that will draw simple diagrams.

Can anyone point me in the right direction please?

 

TIA

Embedded developer, www.ambientpower.co.uk
Ukulele stuff, www.coolcatukes.com
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

try 

testline.x1="20";

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

try 

testline.x1="20";

Best Answer
0 Votes

Thanks, although I don't need the 20 in quotes. 🙂

Embedded developer, www.ambientpower.co.uk
Ukulele stuff, www.coolcatukes.com
Best Answer
0 Votes