Automaticly adding class to links

Discussion in 'JavaScript' started by Patric69, Mar 9, 2009.

  1. #1
    Ok, first of, Hi. My name is Patric and I'm a total newbi on scripting of any kind. I have stumbled upon a site popup preview script from ShrinkTheWeb.com.

    Now this one shows a popup preview when adding a class to any given link. Now there is a tweak to this. And this is to have that class autonaticly added to ANY link on the site without manually putting the class in there.

    This code:
    
    <script type="text/javascript"> 
    $(document).ready(function() { 
    $("a").each(function() { 
    var cur_source = $(this).attr("href"); 
    if (cur_source) { 
    if (cur_source.search("http://") != -1) { 
    $(this).addClass("stwpopup"); 
    } 
    } 
    }) 
    }); 
    </script> 
     
    Code (markup):
    Now, Applying this to my site, makes every link show a popup preview. Even those which are on my own site (internal links). How is it possible to exclude a domain in that piece of code I posted ?

    The opposite of this I can do, hehe that's easy. It's just to add a domain name to:

    
    <script type="text/javascript"> 
    $(document).ready(function() { 
    $("a").each(function() { 
    var cur_source = $(this).attr("href"); 
    if (cur_source) { 
    if (cur_source.search("http://DOMAIN NAME.COM") != -1) { 
    $(this).addClass("stwpopup"); 
    } 
    } 
    }) 
    }); 
    </script> 
    
    Code (markup):

    This is making every link WITHIN my domain use the preview, but no other. How can I make it the opposite, that is NOT show my internal links.

    Regards Patric.
     
    Patric69, Mar 9, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    if (cur_source.search("http://") != -1 && cur_source.search("mydomain.com") == -1) {
     
    dimitar christoff, Mar 9, 2009 IP