Clearing TODO


#1

https://www.codecademy.com/courses/jquery-ext/projects/jquery-prj_listeasy?user_id=51a639966029deef0b000241

Cannot get the text to clear from Add Item Box


var template = function(text) {
  return '<p><input type="checkbox"><i class="glyphicon glyphicon-star"></i><span>' + text + '</span><i class="glyphicon glyphicon-remove"></i></p>';
};

var main = function() {
  $('form').submit(function() {
    var text = $('#todo').val();
    var html = template(text);
    $('.list').append(html);
    $('#todo').remove(text);
    
    return false;  
  });
  
};

$(document).ready(main);


#2

Hi Brian,

I'm not a jQuery whiz so I can't fully explain the "why" of this, but, from the docs, it looks like remove is good for removing a whole element. In this case you don't want to remove the element, just the text. I would try using val() to set the value of your #todo to "", like this:

$('#todo').val("");

I wouldn't be surprised if someone came along with a better solution. :smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.