freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/jquery/target-elements-by-id-using...

1.1 KiB

id title challengeType forumTopicId required
bad87fee1348bd9aeda08826 使用 jQuery 配合 id 选择器选择元素 6 18317
link
https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css

--description--

你也能通过 id 属性选取标签。

首先,用$("#target3")选择器选取 id 为target3button标签。

注意,和 CSS 属性一样,在 id 名前需要添加#

然后,用 jQuery 的.addClass()方法添加animatedfadeOut类。

下面的代码的效果是使 id 为target6button标签淡出:

$("#target6").addClass("animated fadeOut").

--hints--

用 jQuery 的addClass()方法给idtarget3button标签添加animated类。

assert($('#target3').hasClass('animated'));

用 jQuery 的addClass()方法给idtarget3的标签的类添加fadeOut类。

assert(
  ($('#target3').hasClass('fadeOut') || $('#target3').hasClass('fadeout')) &&
    code.match(/\$\(\s*.#target3.\s*\)/g)
);

仅用 jQuery 给标签设置类。

assert(!code.match(/class.*animated/g));

--solutions--