Question about targeting same element with multiple jQuery selectors

Why did we have to use both button and btn? Why dont we just use btn and use classes animated and shake? Why is it important use Animted in Button and Shake in Btn? And why did we have to use animated shake btn-primary in target1? Im kinda confused in this one?

1 Like

In this case, they’re interchangeable - all <button> elements also have the class btn. It’s possible for this to not be true. I believe the purpose of this exercise is to show that you can target both a class and an element. You’re correct, though, that in a real app you’d want to just use one or the other (probably creating a class just for the purpose of targeting animations).

1 Like

I read one reply down there in Get Hint and i understood all of this. But im still curious if we could just use button or ,btn and just put animated shake and use btn-primary or any other btn color all together.

Technically, it’s possible to use $('.btn').addClass("animated shake"). Of course, any other element, class, or id selector will work so long as it selects what you want. This particular exercise may be checking for specific code, so you might not be able to use that here.