0

I'm geting an Uncaught TypeError: Object is not a function

on WordPress when trying to filter a table using jQuery, my code is the following one. It works when it's not under WordPress so I guess I'm missing some kind of wrapping code on some function

Thanks to anyone who can save me in here!

Code:

<script type="text/javascript">
    var link = true;
    //<![CDATA[ 
    jQuery(window).load(function($) {
        jQuery("#searchInput").keyup(function($) {
            //split the current value of searchInput

            //create a jquery object of the rows
            var jo = $("#fbody").find("tr");
            if (this.value == "") {
                jo.show();
                return;
            }
            //hide all the rows
            jo.hide();

            //Recusively filter the jquery object to get results.
            jo.filter(function(i, v) {
                var $t = $(this);
                for (var d = 0; d < data.length; ++d) {
                    if ($t.is(":contains('" + data[d] + "')")) {
                        return true;
                    }
                }
                return false;
            })
                    //show the rows that match.
                    .show();
        }).focus(function() {
            this.value = "";
            $(this).css({
                "color": "black"
            });
            $(this).unbind('focus');
        }).css({
            "color": "#C0C0C0"
        });
    });//]]>  
</script>
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
Saikios
  • 3,623
  • 7
  • 37
  • 51
  • 1
    You're getting his error on which line ? – enguerranws Jan 03 '14 at 16:47
  • Does your Wordpress template include a reference to the jQuery library? – Mister Epic Jan 03 '14 at 16:49
  • I don't see anything in your code that would throw that, unless you're doing `window.jQuery = {}` somewhere before this code. If you hadn't included jquery you would instead get undefined isn't a function. – Kevin B Jan 03 '14 at 16:50
  • Hi @enguerranws I got this exact error (anonymous function) ?eventid=9600&submit=Submit:226 x.event.dispatch jquery.js?ver=1.10.2:4 v.handle jquery.js?ver=1.10.2:4 – Saikios Jan 03 '14 at 17:03
  • @KevinB no, this is the first jquery of the code, but had to double check, so thanks for the hint – Saikios Jan 03 '14 at 17:08
  • @Saikios I was wrong, the answer below completely explains why it is happening. I would expect the code in your question to not work anywhere due to overriding `$` in the event handlers. – Kevin B Jan 03 '14 at 17:09
  • @KevinB but you can check it working on the fiddle I posted as a comment down there :( – Saikios Jan 03 '14 at 17:09
  • 1
    Look very closely at your fiddle and the code in your question. there's a very important difference. This spot in particular... `...Input").keyup(function () {...` which is line 5 above. – Kevin B Jan 03 '14 at 17:10
  • @KevinB thanks a lot for the help, my error is not mentioning this before, but if I leave it as it is it will show a lot of errors, explained in here http://stackoverflow.com/questions/10807200/jquery-uncaught-typeerror-property-of-object-object-window-is-not-a-funct – Saikios Jan 03 '14 at 17:26

1 Answers1

2

The first argument of .load() handler (and keyup) is an Event object, these methods don't work like .ready() method, the first argument of the .ready() handler refers to jQuery which is useful for avoiding conflicts with other libraries that use $. So you are (mis)using an Event object as jQuery.

Ram
  • 143,282
  • 16
  • 168
  • 197