li click events on Safari?
This issue is specifically with Safari.
<div id="list">
<ul>
<li onclick="do_something();"><!-- block with st开发者_开发技巧uff in it --></li>
</ul>
</div>
When the above is loaded normally, the onclick applies to the entire li block. The problem is, later on when I use ajax to populate the #list div dynamically...
$("#list").html('<ul><li onclick="do_something();"><!-- block with stuff in it --></li></ul>');
The click event doesn't fire on the entire block but only the part of the block (i.e. the part of the block where content does not exist, the background).
That's strange. You can use jquery events for this though:
$("#list")
.empty()
.append ( $('<ul><li><!-- block with stuff in it --></li></ul>' )
.find('li')
.click(dosomething)
.end()
);
You cannot use, for weird security reasons, onclick while using innerHTML property (which is exactly what html() does). You need to attach events using addEvent(mootools) -> find some relevant method in jquery
精彩评论