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
Conclusion # The "find is not a function" error occurs when we call the find() method on a value that is not of type array. To solve the error, convert the value to an array before calling the find method or make sure to only call the method on arrays.
on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.
jQuery :not() SelectorThe :not() selector selects all elements except the specified element. This is mostly used together with another selector to select everything except the specified element in a group (like in the example above).
You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.
data
is going to be a string.
If you're expecting data
to contain HTML, try
var content = $(data).find(....)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With