Search code examples
javascripthtmlhref

How can i edit the href of this specific class via Javascript?


I can figure out how i can change this href link via Javascript, can you guys help me?

The link i want to change is the above:

Html Screenshot of the Link here

<div class="view-project vp-global  font_rs0r6bbli"><a href="http://decatejo.pt/video-hp">SABER MAIS</a></div></div><div class="section">

Solution

  • You can use document.querySelector('.view-project.vp-global.font_rs0r6bbli a').href to set the href value of the a tag in that class. Use browser's inspect element on that link to check the href value being changed.

    var newHref = 'www.google.com';
    document.querySelector('.view-project.vp-global.font_rs0r6bbli a').href = newHref;
    <div class="view-project vp-global font_rs0r6bbli"><a href="decatejo.pt/video-hp">SABER MAIS</a>