简体   繁体   English

CSS3卡翻转,jQuery返回未定义的函数

[英]CSS3 Card Flip, Jquery returns undefined function

Simple problem, but can't figure it out. 简单的问题,但无法解决。 The following basic lines of jquery are not cooperating with me. jQuery的以下基本行与我不合作。 Browser returns following error: Uncaught TypeError: undefined is not a function 浏览器返回以下错误: 未捕获的TypeError:undefined不是函数

$('.flip').click(function() {
    document.find('#card').addClass('flipped');
});

All the classes and ids called exist in the docs. 所有调用的类和ID都存在于文档中。 No problems there. 那里没有问题。

Remove document and find from document.find('#card').addClass('flipped'); 删除document然后从document.find('#card').addClass('flipped'); find as you don't need that. 因为您不需要那。

  $('.flip').click(function() {
        $('#card').addClass('flipped');
    });

demo: 演示:

http://code-chunk.com/chunks/543b7d86025c1/flip-it http://code-chunk.com/chunks/543b7d86025c1/flip-it

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. 每当jquery无法使用指定的选择器找到元素并且调用任何函数时,即在未定义对象上调用函数时,您都会得到undefined is not a function错误。

You should use find() with document like below 您应该将find()与如下document一起使用

$('.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() 但是,当您尝试查找使用id在整个DOM中必须唯一 ),然后直接使用id选择器而不是find()

$('.flip').click(function() {
    $('#card').addClass('flipped');
});

由于您通过id引用元素,因此可以直接调用它:

$('#card').addClass('flipped');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM