1

$(".link-moto").on("click", function() {
  alert($(this).html())
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<a class="link-moto" target="blank" href="https://www.harley-davidson.com/us/en/index.html">
  Harley-Davidson USA
</a>

1 ответ 1

1

Для того что бы показать значение атрибута в alert'е, нужно сначала его получить:

$("a").on("click", function(event) {
  event.preventDefault()
  const href = $(this).attr("href")
  alert(href)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="link-moto" target="blank" href="https://www.harley-davidson.com/us/en/index.html">Harley-Davidson USA</a>

2

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.