Home » CodeDigest


Selecting HyperLinks based on the Target URL's Extension Using jQuery
Submitted By Satheesh Babu B
On 7/29/2009 8:27:22 AM
Tags: CodeDigest,jQuery  

Selecting Links based on the Target URL's Extension Using jQuery

Sometimes, we will require selecting all the links in a page or DIV that links to a particular extension.


For example, if we want to select all hyperlinks that link to a PDF file extension to style it differently from other links we can use the following jQuery script.


<script src="_scripts/jquery-1.3.2.min.js" type="text/javascript"></script>    
    <script language="javascript">
        $(document).ready(function() {
            $("#dvContent A[href$=pdf]").css("color", "Red");
    <form id="form1" runat="server">
    <div id="dvContent">


The selector expression in above code uses "$" sign at the end of href property indicates to select all the hyperlinks(<A> tag) with href property value ending with "pdf" string. When the above code is executed, it will make all the links inside the DIV "dvContent" with pdf extension to Red.

Happy Coding!!!

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..