2
變化內容我有一個<span>
,我試圖改變對點擊的內容。我已經遵循了幾個教程,但我似乎無法做到正確,所以它會改變。我使用unicode字符,所以我認爲我需要使用.html()
而不是.text()
,但我可能是錯的。任何理由爲什麼這不應該工作?上點擊
這裏是我與
$(document).ready(function() {
$(".dropdownheader").click(function() {
$("#childList").toggle("slow");
if ($("#droparrow").html() == '▸') {
$("#droparrow").html('▾');
} else {
$("#droparrow").html('▸');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dropdownheader">Expected Outcomes of a Corporate Course <span id="droparrow">▾</span></div>
<div id="childList">
<ul>
<li>A better relationship with your coworkers.</li>
<li>A High Trust and open enivornment.</li>
<li>A safe and fun environment to work in.</li>
</ul>
</div>
有沒有'類= 「droparrow」'元素在你的HTML。它是'id =「droparrow」',所以選擇器應該是'#droparrow'。 – Barmar
@Barmar呃,我以爲我解決了這個問題。現在已經修復了。現在它會改變一次,但它不會改變點擊。 –
問題是'.html()'不返回實體代碼,它返回它轉換爲的Unicode字符。嘗試'console.log($(「#droparrow」)。html())'看看。 – Barmar