jQuery和SVG-如何查找'g'标签 [英] JQuery and SVG - how to find the 'g' tag

查看:406
本文介绍了jQuery和SVG-如何查找'g'标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下:

<svg>
    <g id="node1" class="node"></g>
    <g id="node2" class="node"></g>
</svg>

如何找到'g'标签,我希望可以单击所有标签,而不仅仅是'node1'或'node2'.我已经尝试与此类似,但无法使其正常工作.

How can I find the 'g' tag, I want that all tags could be clicked, and not just 'node1' or 'node2'. I've tried simular to this, but could not get it work.

$('g').click(function(){
    alert("Hellooooo");
});

推荐答案

使用find()方法获取更多信息,请访问这个

Use find() method for more info visit this

例如,对于$("body").find("p").css("background-color","#f00");,将所有主体的<p>元素的背景色设置为红色.

For eg $("body").find("p").css("background-color","#f00"); sets all body's <p> element background-color to red.

对于您的问题,请尝试以下操作:

For your question try this:

$("svg").find("g").click(function(){

// your jquery code here

}
);

这篇关于jQuery和SVG-如何查找'g'标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆