jQuery 文字にツールチップを付けるサンプル
環境
Google Chrome 105.0.5195.127
Windows 10 Home 64bit
jquery 3.6.1
構文
$(document).tooltip();
「title」属性がある要素にカーソルを当てるとツールチップが表示されます。
jquery.min.jsに加えてjquery-ui.min.jsとjquery-ui.cssを追加します。
使用例
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function(){
$(document).tooltip();
});
</script>
</head>
<body>
<p><span title="東京品川区">東京</span></p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function(){
$(document).tooltip();
});
</script>
</head>
<body>
<p><span title="東京品川区">東京</span></p>
</body>
</html>
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script> $(function(){ $(document).tooltip(); }); </script> </head> <body> <p><span title="東京品川区">東京</span></p> </body> </html>
結果
「東京」の文字の上にカーソルを当てるとtitle属性の値がツールチップが表示されます。