Search code examples
jquerylanguage-agnosticfunctional-programmingreturn-valuereturn-path

jQuery - return false & append text to DIV


Something in my code isn't working and I'm not sure what it is. I want this function to return false, and at the same time append some text to a DIV

$(document).ready(function(){
$('#newCatchForm').submit(function() {
    if ( !$('#t1')[0].value && !$('#t2')[0].value ) { 
        return false;
        $('#divTest').append("this text was appended");
 }
});
});

Solution

  • return halts execution. Nothing else will get executed after return...

    switch the two around:

    $(document).ready(function(){
      $('#newCatchForm').submit(function() {
        if ( !$('#t1')[0].value && !$('#t2')[0].value ) {
          $('#divTest').append("this text was appended");
          return false;
        }
      });
    });