Page refreshes and my submit doesn't show


#1


I have done this exercise and I checked with other answers here and it seems that it is correct. Although, when I write something and hit enter or click on post, the page refreshes instantly and shows nothing. Any help?


var main = function() {
  $('form').submit(function() {
    var comment = $("#comment").val();
    if(comment !== "") {
      var html = $('<li>').text(comment);
      $(html).prependTo('.comments');
      $('#comment') = val('');
    }
    return false;
  });
};

$(document).ready(main);


#2

Hi @quizan,

There are two small problems with your code:

  1. You shouldn't surround the html variable in a jQuery selector ($(...)), since it's not meant to select an element
  2. val() is a method you call on an element, like this: $(...).val("");, settting $('#comment') equal to whatever it returns won't work.

Fix those, and your code should work :slight_smile: Let me know if you have any more questions!


#3

It worked like a charm! Thank you for your answer!


#4

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