Forums

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
    Posts
  • #253867
    SirenaColella
    Participant

    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: https://codepen.io/Colella/pen/XRmJmO

    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!

    #253868
    Atelierbram
    Participant

    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="http://www.albertotadiello.com/en/alberto-tadiello-work-1/113/"]').textContent = 'Come abitando in prossimità';
    

    or .nodeValue

    document.querySelector('a[href="http://www.albertotadiello.com/en/alberto-tadiello-work-1/113/"]').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.

    https://codepen.io/atelierbram/pen/vmNOOW

    #253871
    SirenaColella
    Participant

    Thanks really much! Thanks <3

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