Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - find not a function?

Tags:

jquery

find

get

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

like image 470
Phil Jackson Avatar asked Aug 20 '10 15:08

Phil Jackson


People also ask

Is not a function at Array find?

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.

Is not a function error jQuery?

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.

How to use not selector in jQuery?

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).

Is not defined in jQuery?

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.


2 Answers

data is going to be a string.

If you're expecting data to contain HTML, try

var content = $(data).find(....)
like image 60
Pekka Avatar answered Sep 28 '22 08:09

Pekka


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.

like image 28
belugabob Avatar answered Sep 28 '22 09:09

belugabob