getElementById
是单数,不是复数。您也不需要.length
,因为它的含义因节点而异。
if( document.getElementById('profile-advanced-details')) {
document.getElementById('page-body').style.height = "1500px";
}
您也可以使用 CSS,但前提是参考元素(“profile-advanced-details”)位于目标(“page-body”)之前。这可能不是这里的情况,但这是一个很好的技巧:
#profile-advanced-details + #page-body,
#profile-advanced-details + * page-body {height:1500px}
/* the following may work in CSS4: */
!#page-body #profile-advanced-details,
!#page_body + #profile-advanced-details,
!#page_body + * #profile-advanced-details {height:1500px}
$#page-body #profile-advanced-details,
$#page_body + #profile-advanced-details,
$#page_body + * #profile-advanced-details {height:1500px}
#page-body! #profile-advanced-details,
#page_body! + #profile-advanced-details,
#page_body! + * #profile-advanced-details {height:1500px}
#page-body$ #profile-advanced-details,
#page_body$ + #profile-advanced-details,
#page_body$ + * #profile-advanced-details {height:1500px}
/* The different ones are partially because I don't remember the spec,
but mostly because it's changing */