so I have a problem, I’m trying to change the .innerHTML of a span of which name changes every time I refresh the page (only some part of that name changes)
so for example I always use this to change the span’s innerHTML:
document.getElementsByClassName('something')[0].innerHTML='new text';
but the problem is that the site now adds random characters after that "something", for example:
<span class="something RANDOM123 random212312">some text</span>
and the question is, is this possible to find this span and change the innerHTML of it just by looking for the first part of the class name which is "something"?
Thanks in advance
>Solution :
Maybe you can use partial selector:
$('[class^="value"]') <-- starts with string
$('[class$="value"]') <-- ends with string
// using jQuery
$('[class^="something"]')[0].innerHTML='new text';
// using document
document.querySelectorAll('[class^="something"]')[1].innerHTML='new other text';
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="something RANDOM123 random212312">some text</span>
<span class="something RANDOM123 random212312">some other text</span>