Solved

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

Posted on 2013-01-24
5
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

751 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