I have a jquery function that changes a text inside a element using a jquery \"text\" function. Inside this td element is child \"a\" tag like this.
If you want to change text in a select menu, you can do this by giving an option an id or class. If you have: Then in your function you should have something like this: However, this will select all links that are direct children of Working Code !! using child-selector Wrap the text in a Edit: Or use You would simply change another element's text. Then invoke like so:
$('selector').children('option[id=option_id]').text('new text');
<td class="v3">
<a href="somelink">text to change</a>
</td>
$("td.v3").children("a").text("new text");
td
s with class .v3
. Adding a .first()
after children should help:$("td.v3").children("a").first().text("new text");
>
with pseudo-class :first-child
const changeIt = () => {
$('div.v3 > a:first-child').text('New Text');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="v3">
<a href="somelink">text to change</a>
</div>
<button onclick="changeIt()">
Click
</button>
span
element, and change the text in the span.<div id="foo">
<span>bar</span>
<a href="#">link</a>
</div>
...
$('#foo span').text('new text');
$('td.v3 a').text("new text")
to change the text in the anchor, if that's what you want to do.<td>
<a href="#">Link</a>
<span>SomeText</span>
</td>
$('td').find('span').text('myNewText');