Lesson: jQuery
Target the same element with multiple jQuery Selectors
Now you know three ways of targeting elements: by type: $("button")
, by class: $(".btn")
, and by id $("#target1")
.
Although it is possible to add multiple classes in a single .addClass()
call, let's add them to the same element in three separate ways.
Using .addClass()
, add only one class at a time to the same element, three different ways:
Add the animated
class to all elements with type button
.
Add the shake
class to all the buttons with class .btn
.
Add the btn-primary
class to the button with id #target1
.
Note
You should only be targeting one element and adding only one class at a time. Altogether, your three individual selectors will end up adding the three classes shake
, animated
, and btn-primary
to #target1
.
The content on this page is licensed under Attribution-ShareAlike 4.0 International. Original authors: freeCodeCamp, the content was modified.