Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery and SVG - how to find the 'g' tag

Imagine this:

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

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");
});
like image 413
Kungen Avatar asked Jun 11 '13 11:06

Kungen


1 Answers

Use find() method for more info visit this

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

}
);
like image 128
Bhojendra Rauniyar Avatar answered Sep 20 '22 12:09

Bhojendra Rauniyar