CSS中“类”目标的功能/目的是什么?

时间:2017-09-30 14:44:25

标签: jquery css class target

首先,我不确定这是一个属于CSS的课程还是什么,我也不是英语母语人士,但我会尽我所能。 我是新编码并在Freecodecamp传递了这个挑战,但不明白为什么我需要添加这个类。我发现了两个类似的问题,并且看了接下来的挑战,但问题和挑战都没有帮助我理解添加这个课程的重点。 挑战的名称是:使用jQuery选择器创建一个目标类。任何帮助表示赞赏。

<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<div class="well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
<div class="col-xs-6">
<div class="well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
</div>
</div>

2 个答案:

答案 0 :(得分:1)

一个类既不属于CSS也不属于JS,但它是构成网站文档对象模型(DOM)的HTML的一部分。

假设你有这个HTML:

<button class="btn">Button</button>

要定位课程,请使用.运算符。

所以在CSS中你定位一个这样的类:

.btn { background-color: red }

在jQuery中你会定位一个这样的类:

$('.btn').css('background-color', 'red');

答案 1 :(得分:0)

To David Yeiser's answer,

You can also use ECMA's method the .querySelector or .querySelectorAll method.

I know it isn't a direct answer to the question on utilizing jQuery, but I feel you can understand how class attributes and id attributes affect the DOM structure by using raw javascript rather than third-party APIs.

For example, in the structure posted:

document.querySelector(".well") 

in your sandbox will return the first instance of a dom object that matches the class well in your document tree whereas:

 document.querySelectorAll(".well") 

will bring an HTML collection of two .class nodes returned to you.

See MDN's document.querySelector的值,以便更好地了解查询html节点。随着jQuery库越来越少地用于替换React,Angular或Vue来编译和隔离用于Web构建的代码,它将会出现在手册中。

相关问题