gpt4 book ai didi

javascript - JQuery addClass 通过 CodePen 上的函数

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:15 25 4
gpt4 key购买 nike

我确定这是一个明显且愚蠢的错误,但我似乎无法在函数调用中添加类:

https://codepen.io/Yonkai/pen/WZyMJw?editors=1111

问题出在JS部分的第28行:

 function smove(){
$(".creatures p:nth-child(2)").addClass("selected");
}

当我调用该函数时,它不会像我预期的那样在 html 中更改“Rodan”,这里(未从哈巴狗编译),我希望它通过添加类变成黄色:

.selected{
color:yellow;
}

进入:

<div class="creatures">
<p class="bodytext">🢂Mothra🢀</p>
<p class="bodytext">🢂Destroyah🢀</p>
<p class="bodytext">🢂Rodan🢀</p>
<p class="bodytext">🢂Kim Jung Un🢀</p>
<p class="bodytext">🢂King Ghidora🢀</p>
<p class="bodytext">🢂Godzilla🢀</p>
</div>

最佳答案

你需要让你的 .selected 选择器在 css 中更具体,比如 div .selected

目前 div .bodytext.selected 有更多的优势

Update Codepen

您可以阅读有关 css 特异性的文章 here

关于javascript - JQuery addClass 通过 CodePen 上的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46699391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com