JS - 获取具有相同 id 的两个元素之间的正确元素

JS - Get the correct element between two with same id

本文关键字:元素 两个 之间 JS id 获取      更新时间:2023-09-26

我有下一段html代码,我想使用JQuery获得带有ajaxresponse_1 id的第二个div,如果我能添加id atribute 会很容易,但我不能。当我使用 $("#ajaxresponse_1") 并将任何人元素附加到其中时,它不起作用。谁能帮我?

<div id="ajaxresponse_1" class="ajaxresponse ajaxresponse_1" style="display: block;">
    <div id="ajaxresponse_1" class="ajaxresponse ajaxresponse_1">
        <h3 class="avia-form-success">O valor do IPVA é R$ 1500</h3>
    </div>
</div>

请使用find function它将帮助您获得第二个div,您也可以使用children function。正如@Steve所建议的,您不应该有多个具有相同ID的元素

$("#ajaxresponse_1").find("div#ajaxresponse_1")