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
Post a Comment