开发者

Add pdf icon for all links using jquery

开发者 https://www.devze.com 2023-03-03 13:16 出处:网络
I have over 1K links in a html page, How do I add a pdf icon just before the link using jquery. Thanks

I have over 1K links in a html page, How do I add a pdf icon just before the link using jquery.

Thanks Jean

[update] @pekka I have added the icon, the icon displays, but it is under the text extreme right. I cannot move the icon with left, or padding-left , because the icon is placed as background-image. Using left开发者_如何学编程: or padding-left moves the links.


With CSS:

a { /* <---- or a class selector to limit the rule to some links */ 

      padding-left: 24px; /* or the width of your icon */
      background-image: url(....);
      background-repeat: no-repeat;
      background-position: left center; /* Adjust if needed */
   }

if your icon's height differs from the links' height, use either padding-top / padding-bottom or line-height to adjust.


This can be done without using JQuery.

a[href$='.pdf'] // this is for all the link which end .pdf extension. so you don;t need jquery  
{  
padding-left: 20px;  
background: url(images/icon_pdf.gif) center left no-repeat;  
}  
0

精彩评论

暂无评论...
验证码 换一张
取 消