Simple problem, but can't figure it out. The following basic lines of jquery are not cooperating with me. Browser returns following error: Uncaught TypeError: undefined is not a function
$('.flip').click(function() {
document.find('#card').addClass('flipped');
});
All the classes and ids called exist in the docs. No problems there.
Remove document
and find
from document.find('#card').addClass('flipped');
as you don't need that.
$('.flip').click(function() {
$('#card').addClass('flipped');
});
demo:
You will get undefined is not a function
error whenever jquery not able to find element using specified selector and you call any function on it ie for function calling on undefined object.
You should use find()
with document
like below
$('.flip').click(function() {
//wrap document inside $()
$(document).find('#card').addClass('flipped');
});
But as you are trying to find using id
( which must be unique through out the DOM ), then use id
selector directly instead of find()
$('.flip').click(function() {
$('#card').addClass('flipped');
});
由于您通过id
引用元素,因此可以直接调用它:
$('#card').addClass('flipped');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.