开发者

Add pdf icon for all links using jquery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜