jquery.load を使用して div にロードした html ファイル内のコンテンツにアクセスしようとしています。
私のインデックスページは次のようになります。
<!DOCTYPE html>
<html>
<head>
<title>
</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="script.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="content">
</div>
</body>
</html>
これまでの私のスクリプトは次のようになります。
$(document).ready(function() {
$("#content").load("content.html");
$("#content").click(function(){
alert($(this).attr("id"));
});
});
content.html ページ:
<!DOCTYPE html>
<html >
<head>
<title></title>
</head>
<body>
<h1 id="header1">
Content
</h1>
<p>
This is a paragraph
</p>
<p>
This is another paragraph
</p>
</body>
</html>
つまり、コンテンツ div のタグをクリックすると、そのタグの ID、つまり「header1」が表示されますが、現在は「コンテンツ」が表示されているだけです。どうすればこれを達成できますか?
前もって感謝します