Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-24
5
Medium Priority
?
188 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)
Suggested Courses

963 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