Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the div id of the known div which is above the known divid.
Posted
Comments
Anup Das Gupta (asteranup) 27-Oct-11 2:49am    
Hi,

Can you explain your problem properly?
radhika 5 27-Oct-11 2:51am    
Ya sure

For example i have 2 div tags and i know the id of the second tag.I need to get the ID of the 1st div tag dynamically using the second div tag Id.Did you get it?
Sergey Alexandrovich Kryukov 27-Oct-11 2:59am    
In principle, this is possible using DOM, but why? Isn't that more appropriate to have an Id for a div in question?
--SA

Hi,

I tried something for your requirement

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script language ="javascript" >
        $(document).ready(function (av) {
         
        });
        function getid(tid) {
            alert(document.getElementById(tid).previousSibling.id);
            
        }
    </script>
 

</head>
<body>
    <form id="form1" runat="server">
    
    <div id="maincontent">
      <div id="frstdiv">this is first div tag</div>
      <div id="scnddiv" onclick="getid(this.id)">this is second div</div>
    </div>
    </form>
</body>
</html></html>


All the Best
 
Share this answer
 
Be more specific to get appropriate answer

if you want to access divid in javascript then use this
JavaScript
var divid=document.getElementById('<%=divid.ClientID %>');
 
Share this answer
 

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