Ticket #10344 (closed bug: invalid)
events not working when using .html(..)
| Reported by: | r.oosterholt | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | manipulation | Version: | 1.5.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When using html(..) to add html to an element, the events in the html are not triggered. This issue is reproducible with the following code in IE7 and 9.
<html>
<head>
<script type="text/javascript" src = "http://kookaburra:8084/FortesIPM/images_etc/scripts/thirdparty/jquery.js?buildNr=5709"></script>
</head>
<body>
Step 1: <div id='ajaxPagedef' style='color:blue'>click here</div>
=> nothing happens in IE7 and IE9<br>
<br>
Step 2:<br>
<div onclick="jQuery('#ajaxPagedef').html(jQuery('#ajaxPagedef').html())" style='color:blue'>click here to fix step 1</div>
=> now clicking Step 1 works and will result in an alert.<br>
<br>
<br>
so after the first html(..) call, the onclick event isn't registered, only after the second html(..) call it is.
<script>
jQuery('#ajaxPagedef').html("<div><div onclick=\"testFunc()\">click</div><script>function testFunc(event) {alert('testFunc');}<\/script></div>");
</script>
</body>
</html>
Change History
comment:2 Changed 20 months ago by timmywil
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to manipulation
Works fine for me in both IE7 and IE9: http://jsfiddle.net/timmywil/9RxGp/
Tho I'm not sure why you would want to add click handlers that way.
Btw, jsfiddle is a little screwy if building the test in IE, but can run tests created in other browsers just fine.
comment:3 Changed 20 months ago by r.oosterholt
Works fine for me in both IE7 and IE9: http://jsfiddle.net/timmywil/9RxGp/
Can anyone else try: its pretty reproducible on my IE7 and IE9...
Tho I'm not sure why you would want to add click handlers that way.
Complete html is generated in an old part of our application... I know you can add events in other ways
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

used inline reproduction scenario instead of jsFiffdle because jsFiddle doesn't work in IE7 and IE9 (at least on my machine)...