D
D
damarkuzz2020-04-18 10:37:30
JavaScript
damarkuzz, 2020-04-18 10:37:30

How to substitute title text in a link using JS?

How to do. so that when you click on a link, the title with the class .maintitleis substituted at the end of the path of this link and goes to it?

<h1 class="maintitle">Музей Искусств</h1>
<a class="map-link" href="https://yandex.ru/maps/krasnodar/"></a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-04-18
@damarkuzz

  1. Attach a click event handler to the required link
  2. In the handler:
    1. Find element.maintitle
    2. Get its text (or any property)
    3. Change the property hrefof the clicked link

  3. If the handler has not canceled the default action, then the browser will continue to process the link will go to the changed URL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question