Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have two functions. One function draw rectangle and other function writes text. I want to create a group so that the text can be displayed inside the rectangles. Otherwise only rectangle is displayed. so i need a javascript funtion to create a group. Thanx
Code:
JavaScript
function drawline(x1, y1, x2, y2) {
         line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
         line.setAttribute("id", "myline
         line.setAttribute("stroke", "black");
         line.setAttribute("stroke-width", "2");
         line.setAttribute("x1", x1);
         line.setAttribute("y1", y1);
         line.setAttribute("x2", x2);
         line.setAttribute("y2", y2
         mainSvg.appendChild(line);
     }

     function drawtext(x, y, value) {
         text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
         text.setAttribute("id", "mytext");
         text.setAttribute("fill", "black");
         text.setAttribute("x", x);
         text.setAttribute("y", y);
         text.textContent= value;
         document.body.appendChild(text);
         mainSvg.appendChild(text);
     }


Thankful,
Usama Javed
Posted
Comments
enhzflep 9-May-13 21:52pm    
I need lots of things too. :-p
But to be serious, what's your question?

Stating a desire and an inability to achieve it, do not make a question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900