id가없는 자식 노드가 여러 개인 경우 ParentNode에 일부 콘텐츠를 추가하는 가장 좋은 방법은 무엇일까요?javascript : parentNode에 일부 콘텐츠 추가
<div class="parent_div">
<div class="child_div_1" > I need to add contents inside this div </div>
<div class ="child_div_2" onmouseover="addClass(this)"> </div>
</div>
My possible solution : function addClass(obj) {
obj.parentNode.firstChild.appendChild(...);
}
하지만 난 누군가가 그 다음 무엇을 첫째 아이의 위치를 변경 의심하는 경우가 있습니다
조건
은? 이 문제를 해결하는 가장 좋은 방법은 무엇일까?
이것은 ID를 정의 할 수없는 유일한 엄격한 조건입니다. –
어떤 경우에는 클래스 이름을 사용해야합니다 (예제에 따라 고유해야 함). – EMMERICH