Reputation: 2884
I know how to get element in jquery by id or class or by using find but I have an element like the following and I want to find it and change the text inside(here is test):
<text x="524" text-anchor="end" zIndex="8" style="cursor:pointer;color:#909090;font-size:9px;fill:#909090;" y="170">test</text>
but the problem is that here this text element does not have any id and I have so many text element in the html file so is there anyway that I can access just this text element(I also can not add id to this text because is created by plugin) ?
Upvotes: 0
Views: 58
Reputation: 647
To select elements based on content, use $(":contains('text')")
See: http://api.jquery.com/contains-selector/
Ans then you can edit the text like this.
$("text:contains('theTextYouKnowIsInside')").html("newText");
Upvotes: 2
Reputation: 5224
You could access via any of following methods :
$("text[x=524]").html("here is test");
$("text[x=524][y=170]").html("here is test");
$("text[y=170]").html("here is test");
here is the demo JsFiddle
Upvotes: 1