javascript - Jquery doesn't work on HTML tags which via called by AJAX -
i have unordered list
<ul id="showlist"></ul>
if user calls ajax function fills list items like
<ul> <li>a</li> <li>b</li> <li>c</li> <li>d</li> </ul>
my problem begins after that. have <script>
tag @ , of page. says when down button pressed make first child of <ul>
blue. nothing
<script> $(body).keydown(function(e) { if(e.keycode == 40){ $("#showlist:first-child").attr("style","background-color:blue"); } }) </script>
how can solve problem?
use $('body')
instead of $(body)
.
you have issue selector:
$("#showlist li:first-child")
working example: http://jsfiddle.net/hf6lf/
also, mentioned in post script @ end of page. if had script in head, need wait dom ready body
element exist. might safer bind handler document
, exist.
Comments
Post a Comment