jQueryを使用してWebページ上のテキストを展開/折りたたむ方法を学習しようとしていますが、「a href」リンクを使用してこれを行う方法がわかりません。私は、 "Show more"リンクをクリックしてテキストを拡大または縮小したいと思います。私はあなたがこれを行うには、非表示のクラスを追加または削除する必要があることを知っていますが、これを達成するためにトグルクラスをどのように正確に使うのですか?jQueryを使用したテキストの展開または折りたたみ
* {
margin: 0;
padding: 0;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 87.5%;
width: 650px;
margin: 0 auto;
padding: 15px 25px; \t
border: 3px solid blue;
}
h1 {
font-size: 150%;
}
h2 {
font-size: 120%;
padding: .25em 0 .25em 25px;
}
div.hide {
display: none;
}
ul {
padding-left: 45px;
}
li {
padding-bottom: .4em;
}
p, a {
padding-bottom: .4em;
padding-left: 25px;
}
a, a:focus, a:hover {
color: blue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="main.css">
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="subset_expansion.js"></script> \t
</head>
<body>
<main id="jdom">
<h1>Expanding and Collapsing messages</h1>
<h2>Message 1</h2>
<div>
<p>Click the link below to expand this message</p>
</div>
<div class="hide">
<p>Hello!</p>
</div>
<a href="#">Show more</a> \t \t \t
<h2>Message 2</h2>
<div>
<p>Click the link below to expand this message</p>
</div>
<div class="hide">
<p>BOOP</p>
</div>
<a href="#">Show more</a>
<h2>Message 3</h2>
<div>
<p>Click the link below to expance this message</p>
</div>
<div class="hide">
<p>Things to do when you're bored</p>
<ul>
<li>Go for a walk</li>
<li>Try your hand at painting.</li>
<li>Listen to music</li>
</ul>
</div>
<a href="#">Show more</a> \t
</main>
</body>
</html>
あなたのjsコードはどこですか? –
コードエディタポップアップに「整頓」ボタンがあります。それを使用してください。 – Rajesh
Chek my codeスニペット。私は靴にコードを提供しました。 –