javascript - Get hovered word from hover() in Jquery? -


i want make auto translate word mouse on over it. use

$('p').hover(function () {   var hoveredword = $(this).text();   translate(hoveredword, 'en'); // function translate word english language }); 

it return whole text within paragraph, however, want word hover not whole text. there function in jquery can use archive this? thanks.

i in different way. wrap text content using <span>:

$(function() {    $('p').html(function () {      var cont = [];      return "<span>" + $(this).text().split(" ").join("</span> <span>") + "</span>";    }).on("mouseover", "span", function() {      var hoveredword = $(this).text();      console.log(hoveredword);      // translate(hoveredword, 'en'); // function translate word english language    });  });
span:hover {background: #ccf;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>hello, world! how you?</p>

and won't use hover function. unreliable , deprecated.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -