0
をトグルします。もう一度ボタンをクリックすると削除できます。私はDOMに元UL李を維持する必要があるので、追加することはできません、私はこれは何が必要であると考えていreplaceWithを使用した後に取り外したり取り外したりしますが、クリックするとdivをul liに置き換えて
$("#button").click(function() {
$("#button").toggleClass("newClass");
$("div").replaceWith($("ul li"));
if ($("#button").text() == "ADD UL LI TO DIV") {
$("#button").text("REMOVE DIV CONTENT");
} else {
$("#button").text("ADD UL LI TO DIV");
}
});
#button {
cursor: pointer
}
#button {
background: red
}
#button.newClass {
background: green
}
ul {
display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<span id="button">ADD UL LI TO DIV</span>
<div></div>
divとulの間で切り替えたいですか? – julekgwa
いいえ、私は "ul"の中の "li"を複製してdivに追加し、次にul liの内容でdivを表示/非表示にしたい – MShack
リモートサイトではなく、例全体をここに投稿してください。 [Stack Snippets](https://stackoverflow.blog/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/)を使用して実行可能にすることができます。 – Barmar