javascriptsvgjquery-svg

Get SVG path id using javascript


I am having a svg file ,there i need to get the particular path id using javascript or jquery. How can i do this?

$(document).ready(function(){
$("svg").click(function(){

$(this).find("#lay7").css("fill",color);

});
});

Instead of giving id ("lay7") of path directly i need to get the id dynamically.

REf:http://jsfiddle.net/BKAHg/


Solution

  • That's just the $(this) object itself. Oh and you want to attach the click handler to the path I imagine too.

    $(document).ready(function(){
    $("path").click(function(){
    
    $(this).css("fill",color);
    
    });
    });