Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change innerHTML of span which part of the name changes in time

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading