I have the code below.
When I trigger #tempbutton from #searchbutton (with an object as a parameter), it works fine. But when I'm doing the same thing from #myid, it won't trigger.
Any ideas what I could be doing wrong? Thanks
Here's my code. Please assume getAjax is called from somewhere. It's just that I had to stripped a lot of code to make it short/readable. But that part definitely works. :)
var onclickmyid = function(event, parameters) {
event.preventDefault();
console.log(event.data); //works. it displays the listlength passed
$("#tempbutton").trigger("click", [ "test" ]); // works but obviously, it won't be an object
//$("#tempbutton").trigger("click", [{ name:"test" }]); // doesn't work although it' the same as the one below
};
var onclicktempbutton = function(event, parameters) { console.log(parameters); }
var onclicksearchbutton = function(event) {
event.preventDefault();
$("#tempbutton").trigger("click", [{ name:"test" }]); //works
};
$(document).on("click", "#tempbutton", onclicktempbutton);
$(document).on("click", "#searchbutton", onclicksearchbutton);
function getAjax() {
$.ajax({
url: my-url-here
, cache: false
, dataType: "json"
, data: {}
, success: function(data, status) {
displayTopicList({ data:data });
}
});
}
function displayTopicList(parameters) {
$.each(parameters.data, function(index, option) {
$("#mylinks").append($("<a></a><br />").attr("id", "myid"+option.id).attr("href", "javascript:void(0)");
});
$(document).on("click", "[id^=myid]", { listlength:parameters.data.length }, onclickmyid);
}