Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jquery a tag onclick

Status
Not open for further replies.

merlinx

Programmer
Sep 20, 2002
170
DE
I'm working on a project where I need to use something like bind, on, onclick or such.

I have a navigation setup with a ul li structure,

<ul>
<li> </li>
<li> </li>
<li>
<ul>
<li><a class="mennav" name="t2">item 1</a></li>
<li><a class="mennav" name="t3">item 2</a></li>
</ul>
</li>
</ul>

since all of this is generated through php, I don't know in advance how many items and name tags will exist.

Important; I have to use the name property and only where <a> has a name tag.

there will be no other <a> tags in the document a name tag, only these, so perhaps it's not necessary to go through the ul li ul li a sequence.


perhaps something this nature,

$(a name).bind('click', function() {
var name;
alert('User clicked on name');
});
 
found a solution,

Code:
$(document).ready(function() {
   $("li ul li a").each(function(index) {
      if($(this).attr("name")){
         alert($(this).attr("name"));
         }
      });
   });

in this case alert will be replaced with other functional code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top