사람이이 코드 끔찍한 덩어리 멀리 할 수있는 선택을 제공 할 수있는이 끔찍한 코드를 제거합니다 :좋은 선택
// img is the image element...
var descriptionContent = $(".descriptionContent", img.parent("td").parent("tr").next("tr"));
HTML은 다음과 같습니다
이<table>
<tr>
<td><img /></td>
</tr>
<tr>
<td><div class="descriptionContent" /></td>
</tr>
<!-- Repeat n times -->
</table>
을 감안할 때 사용자가있다 img를 클릭하면 다음 (그리고 단지 다음) .descriptionContent
요소를 가져와야합니다.
감사합니다, 당신이 뭔가에 이미지를 배치에 대한 걱정 때문에
K
현재 선택이 그다지 무서운 보이지 않는다 . –
정말요? 그러나 나중에 이미지를 래핑하도록 구조를 변경하면 코드를 다시 실행해야합니까? 부모를 선택하게하는 것이 낫지 않겠습니까? – Kieron