I have the HTML elements like the following:

<svg width="930" height="450">
  <g transform="translate(.5,.5)">
    <g class="cell" transform="translate(758.6842105263157,0)">
      <text x="85.65789473684211" y="225" dy=".35em" id="text-Summer" text-anchor="middle"  style="display: block;">Summer</text>
    </g>
   <g class="cell" transform="translate(758.6842105263157,0)">
      <text x="85.65789473684211" y="225" dy=".35em" id="text-Winter" text-anchor="middle" style="display: block;">Winter</text>
    </g>
  </g>
</svg>

How can I get the "id" of the svg:text element which is having the text content "Summer" in Javscript.

I tried accessing using

$("svg g text[text='Summer']").attr('id'). 

But it is not getting.

有帮助吗?

解决方案 2

You should use something like this:

$("svg g text:contains(Summer)").attr('id')

It means that your selector is not correct.

其他提示

Sorry, but what for do you need this? Can't you just generate id and text at one time and then get the element with $("svg g text#text-Summer")?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top