I am creating my content dynamically, When a anchor tag is clicked navigate() function is called. How can i determine which anchor tag was clicked?
function navigate()
{
//var location=$(this).attr("id");
switch(location)
{
/*case "Configuration": $('#detailTable').empty();
$('#detailTable').append(navigateConfig);
break;*/
default: alert(location+" a tag was clicked");
}
}
$('#detailTable').empty();
$('<div width="100%">')
.attr('id','javainfoSpan')
.html('<div class="titleBlue"><a href="javascript:navigate();">Configuration</a>>'+productname+'>Java Properties</div>'+
//some other stuff
'</div>')
.appendTo('#detailTable');
Update:
My question is simple
- there will be a number of
aelements insidedetailTable. - how can I get to know in some js function, which
aelement was clicked?
I see what you’re doing now, you’re creating the
aelements on the fly. If you calljavascript:navigate()then you’re using standard javascript, and not jquery (jquery is required to use the$(this)selector).Instead you should have this:
This will catch the click event in jquery for any a element that you either create on the fly or that’s already there when the page loads.
Remember, if you’re using
idthen you need to set theidattr on theaelement.