I want to implement a kana-helper into my website: When the user hovers over a kana (japanese character) it shall output the right translation.
I have found this: How to get a word under cursor using JavaScript?
jsfiddle
html:
<p>Each word will be wrapped in a span.</p>
<p>A second paragraph here.</p>
Word: <span id="word"></span>
js:
// wrap words in spans
$('p').each(function() {
var $this = $(this);
$this.html($this.text().replace(/\b(\w+)\b/g, "<span>$1</span>"));
});
// bind to each span
$('p span').hover(
function() { $('#word').text($(this).css('background-color','#ffff66').text()); },
function() { $('#word').text(''); $(this).css('background-color',''); }
);
but i am a very beginner in JavaScript and i am not able to rewrite it to my needs. I do not need to automatically set spans, I will do it manually.
For example I have this:
<span id="sho">しょ</span><span id="ha">は</span><span id="n">ん</span>
When the mouse hovers over one of these characters I want to display a translation of it at a fixed position on the page:
しょ = "sho"
は = "ha" or particle "wa"
ん = "n"
(one at a time)