单击鼠标更改SVG字体大小

我正在尝试使用以下方法更改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'); }); });