Solved

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

Posted on 2013-01-24
5
157 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now