Thanks all who responsed to "How to set a link to svg element by JavaScript" . Doug's code works.
This time I have a new question. To open the link in a new window, I added the following line in Doug's code(see below for details): newA.setAttributeNS(xlinkns, 'target','_blank'); But the link page still came on the same window. Please advise. Regards, Spring --- In svg-developers@yahoogroups.com, "Doug Schepers" <[EMAIL PROTECTED]> wrote: > Hi, Spring- > > You're making some wrong assumptions about SVG. > > 1) In order for text to show up, you must have a 'text' element, not simply > place text in a container element like an 'a' element; > > 2) You cannot create a DOM object by simply making a string; you must create > a new element from scratch. Try something like this (assuming that the > 'varLink' element exists): > > var svgns = 'http://www.w3.org/2000/svg'; > var xlinkns = 'http://www.w3.org/1999/xlink'; > > var newA = SVGDocument.createElementNS(svgns, 'a'); > newA.setAttributeNS(xlinkns, 'xlink:href', 'http://www.yahoo.com'); > > var newText = SVGDocument.createElementNS(svgns, 'text'); > newText.setAttributeNS(null, 'x', 15); > newText.setAttributeNS(null, 'y', 30); > > var labelText = SVGDocument.createTextNode('Here is a link'); > newText.appendChild(labelText); > > newA.appendChild( newText ); > > var varLink = svgDoc.getElementById('varLink'); > varLink.appendChild(newA); > > > Hope that helps- > Doug > > doug . schepers @ vectoreal.com > www.vectoreal.com ...for scalable solutions. > > > tangdm wrote: > | > | > | Hi All, > | > | I need to set different links(.pdf, .doc, .ppt) to a svg > | element, say varLink when I click on different map objects. > | > | > | I failed when I tried to change the node value of the varLink in my > | javaScript by > | > | svgDoc.getElementById("varLink").firstChild.nodeValue="<a > | href='http://www.yahoo.com'> Here is a link</a>"; > | > | Please advise how it will work. > | > | Regards, > | > | Spring ----- To unsubscribe send a message to: [EMAIL PROTECTED] -or- visit http://groups.yahoo.com/group/svg-developers and click "edit my membership" ---- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/svg-developers/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/