Results 1 to 4 of 4

Thread: remove href tags from links

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default remove href tags from links

    Hello Everybody, For my site, I would like to remove the href tags from all links created by users. So i added the following code to the header session of my site.

    <script type="text/javascript">
    jQuery(document).ready(function($) {
    $("a").filter(function() {
    return this.hostname && this.hostname !== location.hostname;
    }).addClass('external').attr("target", "_blank").removeAttr('href');
    });
    </script>

    Its working fine, except that, it also removes the links to my subdomains. Can anybody please help me? I just want to remove the href tag only from contents inside a particular div "pagebody".

    Thankyou all

  2. #2
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    If the particular div you want to target has the id="pagebody" you could do something like this
    Code:
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    $("#pagebody a").filter(function() {
    return this.hostname && this.hostname !== location.hostname;
    }).addClass('external').attr("target", "_blank").removeAttr('href');
    });
    </script>

  3. The Following User Says Thank You to azoomer For This Useful Post:

    drsanupmoideen (08-11-2010)

  4. #3
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you azoomer, it worked.
    Last edited by drsanupmoideen; 08-11-2010 at 01:38 PM.

  5. #4
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Is it possible to add some exclusions to this? Just like, if the link url == googel.co/ wikipedia.com etc, dont strip the href tags?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •