const carouselModal = document.querySelector("sdf-carousel-item");
const carouselSlideOne = carouselModal.querySelector("#first");
if (carouselSlideOne){
console.log("carousel slide one is here");
} else {console.log("carousel slide one not here.")}
<sdf-carousel-item id="first" style="height: auto; display: block; width: 50%;" role="group" aria-roledescription="slide" aria-label="1 of 2" class="first-in-page last-in-page active">test one</sdf-carousel-item>
const carouselModal = document.querySelector("sdf-carousel-item");
const carouselSlideOne = carouselModal.querySelector("#first");
if (carouselSlideOne){
console.log("carousel slide one is here");
} else {console.log("carousel slide one not here.")}
你必须替换
const carouselSlideOne = carouselModal.querySelector("#first");
const carouselSlideOne = document.querySelector("#first");
"carousel slide one is here"
其他选项可能是
const carouselSlideOne = document.getElementById("first");
请参见document的文档。