0
중첩 된 요소의 첫번째 ID를 얻을 수 있습니다 :방법이 정확하게 내 질문에 대답해야 jQuery를
How to get the first child id inside the div using JQuery
을하지만 난 그게 부모 요소 자체의 ID를 반환 할 때.
<div id="top-right-container">
<div class="panel panel-inverse" data-sortable-id="products">
<div class="product-heading">
<h4 class="product-title">Products</h4>
</div>
<div class="product-body">
<span class="product-text">Product</span>
<div>
<div id="product-element"></div>
</div>
</div>
</div>
</div>
내가 사용하고있는 JS는 다음과 같습니다 : 내가 가진 HTML은
var topRightContainer = $("#top-right-container:first-child").attr("id");
var bottomRightContainer = $("#bottom-right-container:first-child").attr("id");
console.log(topRightContainer);
콘솔에 출력은 "오른쪽 상단 컨테이너"
어떤 결과가 반환되어야합니까? – Mohammad
이 요소의 ID를 얻으려고합니다 :
– Mike@Mike - 'product-element'를 원하면'$ ("# top-right-container div.product-body div div")를 사용하여 타겟팅 할 수 있습니다. .attr ("id");'클래스 또는 데이터 속성을'product-element' div에 추가하면 더 추울 것입니다. – Krishna