在DOM中获取raphael id属性 [英] Getting the raphael id attribute in the DOM
问题描述
我已经使用 http://readysetraphael.com/
以下是产生的代码示例:
Here is an example of code produced:
...
path6233.attr({id: 'path6233'
...
我查看了attr文档,但没有提及id作为适当的属性. id属性也不添加到DOM.有什么方法可以使Raphael将此ID添加到DOM中,以便我可以对元素进行样式设置?
I have looked in the attr document and it doesn't mention id as a proper attribute. Neither is the id attribute added to the DOM. Is there some way to make raphael add this ID to the DOM so that I can style the element?
或者,我可以以某种方式轻松地走完所有路径并将id属性添加到真实的DOM ID中吗?
Alternatively, can I somehow walk all the paths and add move the id attr to a real DOM ID easily?
推荐答案
我以前没看过readysetraphael.com,这很漂亮.
I hadn't seen readysetraphael.com before -- that's pretty nifty.
通过Raphael纸元素的forEach方法在给定SVG容器内遍历所有元素应该是相当简单的:
It should be reasonably straightforward to walk all of the elements inside a given SVG container via the Raphael paper element's forEach method:
var i = 0;
paper.forEach(function (el)
{
el.node.setAttribute("id", "node-" + i++ ) );
});
但是我应该问-既然您已经将SVG集成到Raphael中,为什么不简单地使用Raphael以编程方式对其进行样式设置呢?关于您的推理的好奇心促使我提出疑问.
But I should ask -- since you already have your SVGs incorporated into Raphael, why wouldn't you simply use Raphael to style them programmatically? Curiosity about your reasoning prompts me to ask.
这篇关于在DOM中获取raphael id属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!