views:

150

answers:

2

This issue is specifically with Safari.

<div id="list">
    <ul>
        <li onclick="do_something();"><!-- block with stuff 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).

+2  A: 

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()
    );
dmitrig01
This doesn't appear to be solving the problem (the li is only clickable for a small portion, not the entire block). But it does make for a rather interesting way to populate the div. :P
Justin
Might be some CSS. Do you have the page online?
dmitrig01
A: 

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

Yossarian
Can you specify? When using ajax, the onclick seems to be working, but only for a portion of the <li> and not the entire block (because the block has other divs in it). This contrasts with when the page is loaded normally, the onclick fires on the entire block.
Justin