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

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -