Checking if a selector and a method combination worked

Checking if a selector and a method combination worked

I want to test if something was successfully appended because I do not know if the selector worked (actually selected anything or even was a valid selector).

I read that you can test if a selector worked with

  1. if ( $('#someDiv').length ){
  2. }


But would this also work for
  1. if ( $('#someDiv').append('<p>appended</p>').length ){
  2. }

Or do I need to do a plain selection first without a chained function, and then append, as in the first example?