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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -