我一直在這一段時間,我似乎無法破解它..我有一些JavaScript試圖隱藏兄弟divs,除了一個通過函數。這裏的HTML:javascript,無法檢索兄弟節點
<div id = "chat_content">
<div id = "chat_content_1">This is div one</div>
<div id = "chat_content_2">This is div two</div>
<div id = "chat_content_3">This is div three</div>
</div>
而這裏的JavaScript的:
function showGroup(id)
{
// show the the div that was clicked
var e = document.getElementById(id);
e.style.display = 'block';
// hide the others divs under the same parent
var children = e.parentNode.childNodes;
for (var i = 0; i < children.length; i++)
{
if (children[i] != e)
{
children[i].style.display = 'none';
}
};
}
的感謝!和節日快樂:)
謝謝你。也應該是兄弟姐妹()! – Matt