Is there is a smooth way to only let the inner element of a listitem do something? I read something here that using live complicates things.
Summation:
I have list elements that can contain a
elements with a certain class.
The inner a
elements are bound to a live click event handler.
The list items themselves have also a click event handler.
Something like this
<li>some text<a class="someClassName">some text</a></li>
with the handler for the a
tags
$('#somelist li a').live("click", function(e)
and this is how the event for li item is added
$(markers).each(function(i,marker){
$("<li />")
.html("Locatie "+'<a class="ol id"><strong>'+ids[i]+'</strong></a>')
.click(function(e){
showLocation(marker, i);
})
.appendTo("#somelist ");
Solution
Changing the click event above to .live("click", function(e) diddn't work. Instead I added all the a tags like above, so no mixup with live anymore. The solution from Alex might also work, and that way you could have all functionality contained in one function.
For now it turned out like this
$(markers).each(function(i,marker){
listitem = $("<li />")
.html("Location ")
.click(function(e){
showLocation(marker, i);
})
.appendTo("#somelist");
$("<a />")
.html("<strong>"+ids[i]+"</strong>")
.addClass('ol id')
.click(function(){
$('#ginfo').show();
return false;
})
.appendTo(listitem);
oh, and this one has a nice picture to explain the bubbling
thanks, Richard