I have a generated jqueryui accordion code like this:
<div id="treeview-accordion">
<h3><a href="#" accindex="0">Basic</a></h3>
<div>
<ul class="navigation-treeview treeview-sanjo" id="yw0">
<li><span style="font-weight:bold"><a href="/sanjo/site/index"> Home</a></span>
<ul>
<li><span> Profile</span>
<ul>
<li><span><a href="/sanjo/user/profile"> View Profile</a></span></li>
<li><span><a href="/sanjo/user/profile/edit"> Update Profile</a></span></li>
<li><span><a href="/sanjo/user/profile/changepassword"> Change Password</a></span></li>
</ul>
</li>
</ul>
</li>
<li><span> Personnel Management</span>
<ul>
<li><span><a href="/sanjo/user/admin"> Manage Personnel</a></span>
<ul>
<li><span><a href="/sanjo/user"> List Personnel</a></span></li>
<li><span> Add Personnel</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<h3><a href="#" accindex="0">Basic2</a></h3>
<div>
<ul class="navigation-treeview treeview-sanjo" id="yw01">
<li><span style="font-weight:bold"><a href="/sanjo/site/index2"> Home2</a></span>
<ul>
<li><span> Profile</span>
<ul>
<li><span><a href="/sanjo/user/profile2"> View Profile2</a></span></li>
<li><span><a href="/sanjo/user/profile/edit2"> Update Profile2</a></span></li>
<li><span><a href="/sanjo/user/profile/changepassword2"> Change Password2</a></span></li>
</ul>
</li>
</ul>
</li>
<li><span> Personnel Management2</span>
<ul>
<li><span><a href="/sanjo/user/admin2"> Manage Personnel2</a></span>
<ul>
<li><span><a href="/sanjo/user2"> List Personnel2</a></span></li>
<li><span> Add Personnel2</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
and what I want to achieve is to get the attribute “accindex” of the appropriate ‘h3’ tag depending on the link clicked.
For example,I clicked on “View Profile”, and since it is located under the “h3” (Basic), I want to get the value of its accindex attribute, which is “0”.
I tried to use closest(), but it is returning “undefined”. I can’t use parents() either.
How could I accomplish such task? Kindly help me out.
Thanks.
First of all “View Profile” link is not inside h3, its in the sibling of h3. Try this
When you click on view profile link try this
Note: In the above code
thisrepresents the anchor which is clicked.