There is a link and a div. How to implement the replacement of the contents of the div content on the link by clicking on the link using Jquery?

<a class="a">Текст1</a> <div class="b">Текст2</div>

    1 answer 1

     $('.a').on('click', (e) => { e.preventDefault(); $('.b').text($('.a').text()); }); 
    • actually why do you need on ? and why not use this inside? - teran am
    • I don’t use jquery at all and I don’t know how cho there is, just helped a person! - Lyuba Ivanova
    • And if I have several links with one class "a"? And you need to substitute the text from the link on which the click was made? This script works, it substitutes all the text from all the links with this class. - Pavel Bogdanov
    • $('.a').on('click', (e) => { e.preventDefault(); $('.b').text($(e.target).text()); }); - Lyuba Ivanova