JavaScript
x
39
39
1
$(document).ready(function() {
2
3
4
$(".addtophundredwatchlist").click(function() {
5
$.ajax({
6
type : "GET",
7
url : "/watchlisttophundred/",
8
success : function(data){
9
var raw_tag = "<ul>";
10
var add_new = "Add New"
11
var json_array = data.json_array;
12
for (var json_count = 0; json_count < json_array.length; json_count++)
13
{
14
var raw_string = "<li id='watchlistitem' class='watchlistitem'>" + "<input type='button' id='watchlistbutton' class='watchlistbutton' value='*'>" + json_array[json_count].watch_list_name + "</li>"
15
raw_tag = raw_tag + raw_string
16
}
17
raw_tag = raw_tag + "<li id='addnew' class='addnew'>" + add_new + "</li>"
18
raw_tag = raw_tag + "</ul>"
19
$(".listwatchlist").html(raw_tag)
20
//$(this).next().toggle();
21
//alert($(".tophundredwatchlist",$(this)).html());
22
//alert($(this).next().val())
23
$(".tophundredwatchlist").toggle();
24
25
}
26
});
27
});
28
29
30
$(".addnew").click(function() {
31
alert("Add New Clicked");
32
$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
33
});
34
35
$(".watchlistitem").click(function() {
36
alert("Add New Clicked");
37
//$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
38
});
39
I have created a list dynamically using JavaScript and I want to invoke click event as go in normally HTML generated list. This is what I have tried so far but I could not fire a single event. Can any one help?
Advertisement
Answer
Try:
$('.addnew').delegate('li', 'click', function ()
{
//add your code here
});
//OR
$('.addnew').live('click', function ()
{
//add your code here
});