Link to home
Start Free TrialLog in
Avatar of jeremyll
jeremyll

asked on

JQuery:Automatic Insertion of Icons for PDF Links

Aim: to place a pdf icon at the end of a hyperlink.

HTML code:
<a href="#">This is a blue document (PDF, 2.3MB)</a>

Front end output:
This is a blue document (PDF, 2.3MB) [imageIcon]

If the value inside the anchor tag contains '(PDF,' and ends with 'b)' ('b' can be either lower or uppercase) then append the image icon at the end.


This is the code I've been trying to fiddle with to get the above criteria:

<script type="text/javascript" src="../jquery-1.3.2.js"></script>
<script type="text/javascript">
    $("document").ready(function() {
       // $("li a[href$=.pdf]").after("<img src='images/small_pdf_icon.gif' align='absbottom' />");
            $("p=.pdf]").after("<img src='images/small_pdf_icon.gif' align='absbottom' />");
            //$("a[pdf][href$=.pdf]").after("<img src='images/small_pdf_icon.gif' align='absbottom' />");
            $("p*=PDF").after("<img src='images/small_pdf_icon.gif' align='absbottom' />");
    });
</script>
ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeremyll
jeremyll

ASKER

@Proculopsis - they both work! but is it possible to have the icon image referenced inside the css or in the jquery script in <head?> tag? I prefer not to put an image tag inside the <body> tag.

Also, can this work without google's api?

Thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Proculopsis, That's great. How can I put just one space between the imageicon and the anchor tag?
I'm actually using another image, which doesn't have sufficient white space to provide a gap.
Proculopsis - LEGEND