jquery hovercard プラグインを使用して、ユーザーが特定のテキスト文字列にカーソルを合わせたときに ajax を使用してテキスト ファイルからテキストを取得しています。これはすべてうまく機能します (以下のコード)。
ここで、テキスト ファイル内にさまざまな div をいくつか作成し (以下を参照)、カーソルが置かれているテキスト文字列に応じて関連する div を取得します。これは Jquery/Ajax で可能ですか? はいの場合、どうすればよいですか?
//テキストファイルの内容
<div id="John_Resig">
<div class="contact">John Resig</div>
<p><strong>Testing testing testing!</strong></p>
<p>And on another line of text : )</p>
</div>
<div id="Tim_Berners_Lee">
<div class="contact">Tim Berners-Lee</div>
<p><strong>Testing testing testing!</strong></p>
<p>And on another line of text : )</p>
</div>
//Jquery/Ajax コード
$(document).ready(function () {
var hoverHTMLDemoAjax = '<div class="demo-cb-tweets"></div>';
$(".demo-ajax").hovercard({
detailsHTML: hoverHTMLDemoAjax,
width: 350,
delay: 500,
cardImgSrc: 'http://ejohn.org/files/short.sm.jpg',
onHoverIn: function () {
$.ajax({
url : "helloworld.txt",
type: 'GET',
dataType: "text",
beforeSend: function () {
$(".demo-cb-tweets").prepend('<p class="loading-text">Loading latest tweets...</p>');
},
success: function (data) {
$(".demo-cb-tweets").empty();
$(".demo-cb-tweets").html(data);
},
complete: function () {
$('.loading-text').remove();
}
});
}
});
});