Child element count returns 'Undefined' in jQuery

Asked

Viewed 42 times

1

I am trying to count child elements of a parent element with jQuery in the HTML I created, but it is returning the value 'Undefined'.

<div class='dataGrid'>
    <div class='dataGrid-item'></div>
    <div class='dataGrid-item'></div>
    <div class='dataGrid-item'></div>
    <div class='dataGrid-item'></div>
    <div class='dataGrid-item'></div>
    <div class='dataGrid-item'></div>
</div>

And the jQuery I incremented was.

<script>
    $(document).ready({
        var qtdGrid = $('div.dataGrid div.dataGrid-item').lenght;
        window.alert(qtdGrid);
    });
</script>

In the console no error is returned, only in the 'Undefined' Alert'.

inserir a descrição da imagem aqui

  • I’m Voting to close this Question as off-topic because ...

1 answer

2


You put lenght instead of length

/// var qtdGrid = $('div.dataGrid div.dataGrid-item').lenght;
///                                                     ^

console.log( [1,2,3,4].length );
///                      ^ exemplo

  • puts that ugly, rsrsrs thank you. I delete the question?

  • 2

    You can delete if you want, because it ends up falling as a typo =)

  • 1

    Could not delete, even gave more trampo do post than HTML code jkkkkk. " You cannot remove this question as other users have put in time and effort to answer it. For more information, [1]visit help center[2]"

  • @Eliseub. just vote to exclude that the community takes care of the rest. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.