0

Hello I can't find out how to delete a specific value from string when clicking on an element with the string value. its for my todo list.

if (window.localStorage.fullName !== undefined) {
alert('Your browser does not support localStorage');
} else {
$(function () {
    console.log('localSorage compitability detected. proceeding...');

global vars & functions

    var tdli = [];

add list items

    $('#tdladd').click(function () {
        $('.todolist ul ul').append("<li class='tdli'>" + $('#tdlinput').val() + "</li>");
        tdli.push($('#tdlinput').val());
        $('#tdlinput').val('');
        var array = tdli + "";
        localStorage.setItem('tdlis', array);
        console.log(array);
        $('#todolist').hide().fadeIn('fast');
    });

remove list items

    $('li').click(function () {
        var itemtoRemove = $(this);
        tdli.splice($.inArray(itemtoRemove, tdli), 1);
        console.log(tdli);
    });

    $('#clearall').click(function () {
        localStorage.clear();
        location.reload();
    });

load list items

    var tdlitems = localStorage.getItem('tdlis');

    var array = tdlitems.split(',');

    tdli.push(array);

    for (var i = 0; i < array.length; i++) {
        array[i] + "<br>";
        $('.todolist ul ul').append("<li>" + array[i] + "</li>");
    };

    console.log(array);


});

}
1
  • 1
    Could you post ALL of your relevant code? It's possible, but I want to write an answer that fits your code. Commented Nov 20, 2014 at 17:59

1 Answer 1

2

Assuming that tdli is a jQuery wrapped set (which itself is an array-like-object), it will have DOM nodes stored instead of another jQuery objects. That means, just go like

var itemtoRemove = this;

and you should be fine.


After you posted your complete code, we can see you're actually pushing string values into your tdli Array, but you try to .splice() objects respectively DOM nodes, which of course doesn't make any sense at all (comparing apples to oranges).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.