I want to get the text of individual selectors, in my case, only the first selector is always displayed: <div id="nick">Текст1</div> , and it is necessary that if I clicked on the third: <div id="nick">Текст3</div> , then brought the text: Text3

The code is:

 <!DOCTYPE html> 

 <div id="nick">Текст1</div><br><br> <div id="nick">Текст2</div><br><br> <div id="nick">Текст3</div><br><br> <div id="nick">Текст4</div><br><br> <div id="nick">Текст5</div> <script> jQuery('div#nick').on('click',function(){jQuery('div#nick').text().index()}){ console.log(); } </script> </body> 

    1 answer 1

    Use $ (this) inside the jquery function

     jQuery('div#nick').on('click',function() { $("#result").html($(this).text()) }) 

    jsfiddle demo

    • one
      And in IE still does not work. There feint div#nick fails. Well, or did not pass before. - Qwertiy
    • The link to the demo does not lead to a demo ... - Qwertiy
    • corrected the link. About ie I will not lie, I don’t know :( - splash58