为什么未应用此jquery .css样式?

我试图了解为什么未从Chrome的调试器控制台中应用<ul>元素.css属性的原因...

Uncaught TypeError: $(...).css is not a function

这是简单的HTML代码:

<html>
<head>
</head>
<body>
<div id="container">
    <ul>
        <li>First item
            <ul>
                <li>Child list item</li>
            </ul>
        </li>
        <li>Second</li>
        <li>Third</li>
        <li>Fourth</li>
    </ul>
</div>
</body>
</html>

jquery css样式:

$("div#container > ul").css('background-color','red')

我缺少什么?

swallowliu1231 回答:为什么未应用此jquery .css样式?

您是否包含了jQuery?从您的html看来,您没有这样做,在这种情况下,正常工作是不正常的

,

正如Ace在接受的答案中所回答的那样,您没有包含jQuery。如果您不包括jQuery文件,那么首先是如何使其工作的,并且永远不会收到jQuery丢失并且$符号已为您解决的错误

 'Uncaught TypeError: $(...).css is not a function'.

无论如何,如果您希望它在不包含jQuery的情况下运行,则可以使用Vanilla JavaScript。
这是您的操作方法:

 var myElement = document.querySelector("#superman");
 myElement.style.backgroundColor = "#D93600";
本文链接:https://www.f2er.com/3156840.html

大家都在问