質問

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