How to load conditionally a script depending on whether element exists in DOM?
drupal_add_js() happens server-side, it can't possibly have exposure to what's in the DOM (unless you pass that info back to the server with AJAX, but that would be a very weird thing to do). The correct solution is the javascript one as you've mentioned.

You want that code to run whenever the DOM is ready, so in the Drupal paradigm immediately inside the attach function of your behaviour:

(function ($) {
  Drupal.behaviors.leftMenuSticky = {
      attach: function (context, settings) {    
        if ($(".full-height").length &gt; 0 ) {
          var contentHeight = $("#main").innerHeight();
          // ...