Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the text/html value from event.target using jQuery [duplicate]

I'm using Clipboard.js and am trying to get the text in a <td> node using the following:

$('.clipboard').click(function(evt) {
    clipboard.copy(evt.target.val()).then(
      function(){console.log("success");},
      function(err){console.log("failure", err);}
    );
});

Obviously .val() is not a valid method on evt.target. What's the correct way of getting the nodes text value using evt here?

like image 721
randombits Avatar asked Nov 27 '22 10:11

randombits


2 Answers

evt.target.innerText

This will give you text value and innerHtml will give you entire content

like image 129
Tanvi B Avatar answered Dec 09 '22 19:12

Tanvi B


It should be

$(evt.target).text()
like image 25
Nafiul Islam Avatar answered Dec 09 '22 18:12

Nafiul Islam