javascript - Get word under mouse pointer -


according (get word under cursor using javascript )link can word under mouse pointer.it's fine english language. change (for arabic language)

<p>سلام به همه</p> word: <span id="word"></span> <script type="text/javascript"> $(function() { // wrap words in spans $('p').each(function() { var $this = $(this); $this.html($this.text().replace(/[^\x00-\x80]+/g, "<span>$1</span>")); }); // bind each span $('p span').hover( function() { $('#word').text($(this).css('background-color','#ffff66').text()); }, function() { $('#word').text(''); $(this).css('background-color',''); } ); }); 

but return '$1' each word. please help!

you need parentheses appear in original regular expression. in regular expression notation, parentheses form "match group" substituted in "$1" in replace string.

$this.html($this.text().replace(/([^\x00-\x80]+)/g, "<span>$1</span>")); 

without match groups in regex, $1 treated literal dollar sign , one.

when have multiple parenthesized match groups, groups used in replace dollar-sign-denoted numbered placeholders in order match groups opened (the first match group replaces $1, second replaces $2, etc).


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -