Click here to Skip to main content
15,885,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have multiple a href ..i want to use same jquery function to be called when any of them is clicked..
so what to use

id/class/name .
for exp.


XML
<a href="#" name="idvalues" id="getvalu2" class="item">test3</a>

<a href="#" name="idvalues" id="getvalu4" class="item">test4</a>


in jquery i want as 


$().click(function {

});
Posted

1 solution

You can sue name property as per following program :

HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
   <script type="text/javascript">
       $(document).ready(function () {
           $("a[name='idvalues']").click(function () {
               alert('hello')
           })
       });
   </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="javascript:void(0)" name="idvalues" id="getvalu2" class="item">test3</a>

        <a href="javascript:void(0)" name="idvalues" id="getvalu4" class="item">test4</a>
    </div>

    </form>
</body>
</html>
 
Share this answer
 
Comments
maulikshah1990 17-Jan-14 5:13am    
thanks...that helped.
Sandeep Singh Shekhawat 17-Jan-14 5:15am    
Sounds good!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900