<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.3.min.js"></script>-->
<script data-require="jquery@2.2.4" data-semver="2.2.4" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="script.js"></script>
<title>jQuery</title>
</head>
<body>
<button onclick='find("眠い");'>’find関数の引数’で検索します</button>
<div id='content'>
<br>
<a>HTMLのQA</a>
<div id="html">読み込みに失敗しました</div>
<a>JSのQA</a>
<div id="js">読み込みに失敗しました</div>
</div>
</body>
</html>
// Code goes here
$(function(){
$("#html").load("html.html");
});
$(function(){
$("#js").load("js.html");
});
function find(word){
$('#content:contains("' + word + '")').each(function(){
var html = $(this).html();
regexp = new RegExp(word, 'g'),
$(this).html(
html.replace(regexp,'<font style="color:red" id="searched">' + word + '</font>')
);
});
var element = document.getElementById("searched"); //同一id複数あるからなんとかなおして
element.scrollIntoView({behavior: "smooth"});
}
/* Styles go here */
<h1>html.htmlの内容です。</h1>
1
23
<BR>
<BR>
a<BR>
<BR>
<BR>
<BR>
<BR>
b<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
c<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
6
<BR>
sd
ネム眠い
<h1>js.htmlの内容です。</h1>
うぇ
えええええ
だるい
眠い