append icon to download links but not if it is an image

Using the following code I want to add an icon to the text link but not to the image link. and I want the image in-line rather than as a background as the usual css background image method doesn't work for link text that wraps lines.

<a href="foobar.pdf"><img src="" /></a>
<br />
<a href="foobar.pdf">Title of the PDF (10MB)</a>

I need to do this with jQuery as I manage a large site (over 4 million pages).

Any pointers appreciated.


Try something like this:

var non_img_link = $("a:not(:has(img))");
var icon = $("<img>", {src: "icon.png"});

// or .prepend() if you prefer

$('a:not(:has(img))') // gets all anchors that do not contain an image.

Using the above selector you can append what is needed to anchors that do not contain an image.

Need Your Help

Is it possible to retrieve database values in php as the type defined in the database instead of type string?

php database casting sqldatatypes

If I define a column in a mysql database as type int, my queries always return the values as type string.

Include a jsp inside another when a button is clicked

java javascript jquery jsp

I have a logout button.Once it is clicked, I want to show a page confirmlogout.jsp and then based on the user's response, the user has to logout or stay there.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.