Solved

JQuery replacement of closing hyperlink tag if http is in the href tag #2

Posted on 2013-01-24
5
167 Views
Last Modified: 2013-02-11
Hi,

In a previous post, an Expert provided a solution that places and image with alternate text next to the links that are to external sites (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_27974488.html).  I need a to revise their solution so that if I add a class="internal" to the link the Jquery will not add the image to the right of the link.
0
Comment
Question by:atljarman
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:soupBoy
ID: 38814846
Odds are there is a better way to do this, possibly within the .filter() method...but I haven't used filter before...

$("a").filter(function() { return $(this).attr("href").indexOf("http")==0; }).not('.internal').after('<span class="dropt" title="Redirect Disclaimer"><img src='images/redirect.png' title='Redirect Disclaimer'/><span style="width:350px;">Text of the Disclaimer Here </span></span>');

Open in new window


I added the .not('.internal') just after .filter()
0
 

Author Comment

by:atljarman
ID: 38815161
Can you modify the jsfiddle?  Unfortunately, jsfiddle isn't allowing the editing of the jquery syntax, at least not from IE8.

What you are saying is this is how it woudl look in the body of the page:

<script>
$("a").filter(function() { return $(this).attr("href").indexOf("http")==0; }).not('.internal').after('<span class="dropt" title="Redirect Disclaimer"><img src='images/redirect.png' title='Redirect Disclaimer'/><span style="width:350px;">Text of the Disclaimer Here </span></span>');
</script>

Just want to double check.  Had to reinstall XP on my mac and will need to also install other software to be able to test this.
0
 
LVL 8

Accepted Solution

by:
soupBoy earned 250 total points
ID: 38815216
Yeah, jsFiddle really only works well on modern browsers...

Here is the modified jsFiddle: Using .not() with .filter()

It does in fact work.

- Chris
0
 

Assisted Solution

by:atljarman
atljarman earned 0 total points
ID: 38815487
What if I wanted to exclude specific domains as well as class="internal".  For example, what if I want to not have the disclaimer on any site that includes google.com or yahoo.com or includes the class internal?  I've increased the value to 350.  Thanks for your help.
0
 

Author Closing Comment

by:atljarman
ID: 38875422
Thanks for your help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question