Uncaught TypeError: undefined is not a function

Lalien-Miles Lamar Coleman

I'm making a plug-in where I can shorten the title of each entry in a forum index if it is too long. However, that is much harder than I expected.

Everything goes fine except when I get to the part where you actually have to print the items onto the DOM.

I get this error:

Uncaught TypeError: undefined is not a function 

Here is my code with a bunch of notes I left to show you how it works.

var minimize = function() {
    $('.segment').each(function(){
        var title_box = $(this).children('.title');
        // Selects the container of the title.
        var title = $(this).children('.title').text().trim();
        // Takes the child title of the each .segment class and selects its innards.
        console.log(title);
        var res = title.split("");
        // Splits the text into an array.
        console.log(res);
        var fragment = [];
        // initializing the empty array
        for (x = 0; x < 4; x++) {
            fragment.push(res[x]);
            console.log(fragment);
            // Loops through to make sure it's not more than 5 characters long
        };
        var final = fragment.join("");
        // Joins the broken up string together.
        title_box.empty();
        final.appendTo(title_box);
    });
};

What do you think I did wrong? And if there's any other ways for me to make this code more efficient, then please don't hesitate to tell me.

Matt Burland

Right here you define fragment as an array:

var fragment = [];

You then populate it and do this:

var final = fragment.join("");

Read the docs on array.join to understand what that function does. In short, it joins your array together into a string

So now when you do this:

final.appendTo(title_box);

You get your TypeError because string doesn't have an appendTo method

What you probably wanted was a jquery object to call appendTo on.

Perhaps you meant:

title_box.text(final);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Uncaught TypeError:Undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function?

From Dev

Uncaught TypeError: undefined is not a function $

From Dev

Twitter Uncaught TypeError: undefined is not a function

From Dev

Reactjs: Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function - Javascript

From Dev

uncaught typeerror undefined is not a function on .empty()

From Dev

uncaught typeerror undefined is not a function in javascript

From Dev

Uncaught TypeError: Undefined is not a function on indexOf

From Dev

Uncaught TypeError: undefined is not a function for datatables

From Dev

Uncaught TypeError: undefined is not a function 'appendTo'

From Dev

Uncaught TypeError: undefined is not a function in datepicker

From Dev

Uncaught TypeError: undefined is not a function with jQuery

From Dev

Uncaught TypeError: undefined is not a function - checkValidity

From Dev

Uncaught TypeError: undefined is not a function:67

From Dev

Uncaught TypeError: undefined is not a function for datatables

From Dev

Another: uncaught typeerror undefined is not a function

From Dev

uncaught typeerror undefined is not a function on .empty()

From Dev

Uncaught TypeError: undefined is not a function in datepicker

From Dev

Uncaught TypeError: undefined is not a function - Slider

From Dev

Uncaught TypeError: undefined is not a function in RefluxJS

From Dev

Uncaught TypeError: undefined is not a function - datatables

From Dev

Uncaught TypeError undefined is not a function anonymous function

From Dev

Uncaught TypeError: undefined is not a function (anonymous function) in Wordpress

From Dev

Uncaught TypeError undefined is not a function anonymous function

Related Related

  1. 1

    Uncaught TypeError:Undefined is not a function

  2. 2

    Uncaught TypeError: undefined is not a function

  3. 3

    Uncaught TypeError: undefined is not a function

  4. 4

    Uncaught TypeError: undefined is not a function

  5. 5

    Uncaught TypeError: undefined is not a function

  6. 6

    Uncaught TypeError: undefined is not a function?

  7. 7

    Uncaught TypeError: undefined is not a function $

  8. 8

    Twitter Uncaught TypeError: undefined is not a function

  9. 9

    Reactjs: Uncaught TypeError: undefined is not a function

  10. 10

    Uncaught TypeError: undefined is not a function - Javascript

  11. 11

    uncaught typeerror undefined is not a function on .empty()

  12. 12

    uncaught typeerror undefined is not a function in javascript

  13. 13

    Uncaught TypeError: Undefined is not a function on indexOf

  14. 14

    Uncaught TypeError: undefined is not a function for datatables

  15. 15

    Uncaught TypeError: undefined is not a function 'appendTo'

  16. 16

    Uncaught TypeError: undefined is not a function in datepicker

  17. 17

    Uncaught TypeError: undefined is not a function with jQuery

  18. 18

    Uncaught TypeError: undefined is not a function - checkValidity

  19. 19

    Uncaught TypeError: undefined is not a function:67

  20. 20

    Uncaught TypeError: undefined is not a function for datatables

  21. 21

    Another: uncaught typeerror undefined is not a function

  22. 22

    uncaught typeerror undefined is not a function on .empty()

  23. 23

    Uncaught TypeError: undefined is not a function in datepicker

  24. 24

    Uncaught TypeError: undefined is not a function - Slider

  25. 25

    Uncaught TypeError: undefined is not a function in RefluxJS

  26. 26

    Uncaught TypeError: undefined is not a function - datatables

  27. 27

    Uncaught TypeError undefined is not a function anonymous function

  28. 28

    Uncaught TypeError: undefined is not a function (anonymous function) in Wordpress

  29. 29

    Uncaught TypeError undefined is not a function anonymous function

HotTag

Archive