Hello!
I'm having some trouble with a list item which I want a click event to bind to. I've been trying alot of different stuff but without any luck. See code:
- var list = $("<li>");
- var details = $("<a>").text("Get more");
- $(details).prop("href", "#");
- $(details).attr("id", "getMorePosts");
- $("a#getMorePosts").bind('click', (getMorePosts()));
- details.appendTo(list);
- $(list).appendTo("#postsList");
The code above is what I would like to get working. This code attaches a "Get more posts" at the bottom if a UL with search results. This code, howevere, fires the getMorePosts() automatically, without any click from the user. It doesn't fire again when the li is clicked, so something is wrong.
I've been trying this as well to get the click bind at least working, but still no luck:
- var list = $("<li>");
- var details = $("<a>").text("Get more");
- $(details).prop("href", "#");
- $(details).attr("id", "getMorePosts");
- $("a#getMorePosts").bind('click', (function () {
- alert("WORK GOD DAMN IT!");
- }));
- details.appendTo(list);
- $(list).appendTo("#postsList");
What am I doing wrong?