Here is the snippet of code I use to remove the extra space that WordPress adds to the end of
<?php $custommenu = wp_nav_menu ( array ( 'container_class' => 'my-menu', 'theme_location' => 'primary', 'echo' => 0 ) ); $custommenu = str_replace("\n", "", $custommenu); $custommenu = str_replace("\r", "", $custommenu); echo $custommenu; ?>