Wednesday, March 27, 2013

Difference in eq() and :eq() : becomes significant in case nested div


below : first eq(4) gives 4 div ( including the outer one), where as :eq(4) gives fourth INNER div
this needs to be investigated.




<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="eq.aspx.cs" Inherits="_Default" %>

<!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 language="javascript" src="jquery-1.7.2.min.js" type="text/javascript" ></script>
    <script type="text/javascript">
        $(document).ready(
        function() {
        $("div").eq(4).click(function() { alert("789"); });
        $("div :eq(4)").click(function() { alert("000"); });
        }
        );
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
<div>
    <div>aaa</div>
    <div>bbb</div>
    <div>ccc</div>
    <div>ddd</div>
    <div>eee</div>
</div>
<script type="text/javascript">
    $("div").eq(2).click(function() { alert("123"); });
    $("div :eq(2)").click(function() { alert("456"); });
    </script>
    </form>
</body>
</html>

No comments:

Post a Comment