The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Replace text string with javascript

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #253867

    Hello guys, I need to replace the text of a list item, which is also a link. I’m publishing the code on CodePen because I think it is easier to understand.
    My CodePen link si here:

    I need to show in the output “Come abitando in prossimità” and not “Come abitando in prossimità (As if living nearby)”.

    Will you help me kindly? I am a beginner with javascript in and I’m a bit confused! thank you!


    In Codepen – in the javaScript-tab behind the gear icon – one can add external javaScript. You want to add the link to the jQuery library there: then the code-snippet will work; I tested it.

    Alternatively, with vanilla javaScript, I guess one can do with .textContent:

    document.querySelector('a[href=""]').textContent = 'Come abitando in prossimità';

    or .nodeValue

    document.querySelector('a[href=""]').firstChild.nodeValue = 'Come abitando in prossimità';

    This works, but I am a beginner in javaScript myself, so maybe someone else knows of a better way.


    Thanks really much! Thanks <3

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.