jQuery - find not a function?

强颜欢笑 提交于 2019-12-07 02:38:19

问题


could someone please explain why the following code is throwing an error?

// JavaScript Document
$(document).ready(function(){
    $(".port-box").css("display", "none");
    $('ul#portfolio li a').bind('click', function(){
        var con_id = $(this).attr("id");
        if( con_id.length !== 0 ) {
            $.get('./act_web_designs_portfolio', function(data){
                var content = data.find("#" + con_id + "-content").html();
                alert(content);
            });
            return false;
        }
    });
});

Firefox says:

data.find is not a function

Any help much appreciated, regards, Phil


回答1:


data is going to be a string.

If you're expecting data to contain HTML, try

var content = $(data).find(....)



回答2:


Because data is not a jQuery object - it's usually a string containing the markup of the returned page.

Use $(data).find(...) instead - that will probably do it.



来源:https://stackoverflow.com/questions/3532340/jquery-find-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!