##jqueryのloadで追加した要素を取得できない
jqueryのloadを使って、index.htmlにinner.htmlを入れて、inner.htmlにある要素#sectionを取得できません
$("#section")[0]と記述しても取得することができず、undefinedになります
index.html
html
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <title>test page</title> 6 <script src="jquery.min.js"></script> 7 <script src="index.js"></script> 8</head> 9<body> 10 <div id="jquery_area"></div> 11</body> 12</html>
inner.html
html
1<!DOCTYPE html> 2<html> 3<head> 4 <title>inner</title> 5</head> 6<body> 7 <p>OKOKOK</p> 8 <p id="section">focus</p> 9</body> 10</html>
index.js
js
1$(function(){ 2 3 // $(セレクタ).メソッド 4 $("#jquery_area").load("inner.html"); 5 jquery_area = $("#section")[0] 6 console.log(jquery_area)//undefined 7});
回答1件
あなたの回答
tips
プレビュー