Reputation: 31
I want to add some text to my HTML page in an anchor tag using javascript but there is no id,name,or class present inside that anchor tag. Is there any way to do this. Sample code is given below.
<div>
<table>
<tbody>
<tr>
<th>
<span ng-if="smData.standard==smData.stdnr" class="ng-scope">
<a ng-click="m1(a,b)" class="ng-binding" href="/">
Hello.
</a>
</span>
</th>
</tr>
</tbody>
</table>
</div>
Now I want to add something to Hello(say world.)
Upvotes: 0
Views: 64
Reputation: 44145
Use an attribute selector:
document.querySelector("a[ng-click='m1(a, b)']").innerText += " world.";
<a ng-click="m1(a, b)" class="ng-binding" href="/">Hello</a>
Upvotes: 2
Reputation: 1419
Using selectors to track the HTML elements.
Run code snippet.
function reset() {
document.querySelector("div Table tr span a").innerText += " World!"
// $("div Table tr span a").text("Hello World");
}
<!--script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script-->
<button onclick="reset()">Change Text</button>
<div>
<table>
<tbody>
<tr>
<th>
<span ng-if="smData.standard==smData.stdnr" class="ng-scope">
<a ng-click="m1(a,b)" class="ng-binding" href="/">
Hello.
</a>
</span>
</th>
</tr>
</tbody>
</table>
</div>
Upvotes: 1