109Target the same element with multiple jQuery Selectors
说明:
现在你已经了解了3种选择器:元素选择器:$("button")、class选择器:$(".btn")、id选择器:$("#target1")。
尽管用.addClass()这种方式就可以加不同的class,不过还是让我们尝试用不同的方式给元素添加class吧。
用上面介绍的jQuery选择器和addClass()方法:
给所有type为button的元素添加animated class。
给所有class为.btn的按钮添加shake class。
给所有id为#target1的按钮添加btn-primary class。
使用 $("button") 选择器。
使用 $(".btn") 选择器。
使用 $("#target1") 选择器。
在每个选择器中只添加一个 class。
你的 #target1 元素应该有class animated‚ shake 和 btn-primary。
只使用 jQuery来添加这些class到元素中。原始代码:
调试代码:
Last updated
Was this helpful?