开发者

li click events on Safari?

开发者 https://www.devze.com 2022-12-15 03:34 出处:网络
This issue is specifically with Safari. <div id=\"list\"> <ul> <li onclick=\"do_something();\"><!-- block with st开发者_开发技巧uff in it --></li>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消