单击鼠标更改 SVG 字体大小

Change SVG font size with a mouse click

我正在尝试使用此更改 SVG 文本的大小:

$("#text"+x).click(function(){
    //$(this).style("font-size", "4");
    document.getElementById("text"+x).setAttributeNS(null, "font-size", "4px");
    //this.attr("font-size", "4px");
    alert('it is I'); 
});

你可以在那里看到我失败的大部分尝试。我收到弹出警报,但没有任何反应,也没有错误消息。 我已经搜索了网络和 Stack Overflow 无济于事...... 我正在使用 JS + Jquery!

欢迎任何提示!
干杯!

使用下面的代码。检查 DEMO。您需要将 font-size 设置为属性。

 $(document).ready(function(){ 
  $("#text"+x).on('click',function(){
    $(this).attr("font-size", "50");
    alert('it is I'); 
  });
 });

或者如果您要动态添加 svg 元素,请使用以下代码

 $(document).ready(function(){ 
    $(document).on('click',"#text"+x,function(){
      $(this).attr("font-size", "50");
      alert('it is I'); 
    });
 });