问题
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