How to filter out anchors

How to filter out anchors

I have the following code:
  1. <script>
    var siteDomain = 'site.org';
    jQuery(document).ready(function () {
        jQuery("a").not("[href*='"+siteDomain+"'],[href*= + siteDomain + '#'],[href*='javascript'],[name]:not([href])").attr('target','_blank').addClass('external').append(' <span class="hideOffScreen">Opens New Window</span>');

    });

    </script>






One last item that I need for this is the ability to only apply this rule to links that contain href="#top" or any other name for an anchor that point to another domain and leave same page or same site anchors alone.

Suggestions?

Thanks for your time.