Updating contents length / size on click
Hi Everyone, new to the forum.
I don't know how to title this as it's not easy to explain.
I have the following code:
https://jsfiddle.net/xpvt214o/448284/
You can click the - in the right of the widget to send it to trash.
This works beautifully but I want to be able to offer a way for the user to clear the trash "folder".
I first added the following:
- $( '.trashwidgets' ).append( '<a class="cleartrash" href="#">Clear</a>' );
That works but everytime you add a widget to the trash, it duplicates the button, which I don't want. I just want one button to clear it all.
So I tried using the length parameter as follows:
- if( $( '.trashwidgets .cleartrash' ).length <= 1 ) {
- $( '.trashwidgets' ).append( '<a class="cleartrash" href="#">Clear</a>' );
- }