Part of my dom will be created after page loaded (by ajax). For those generated-dom-after-page-load, my code doesn't work (nothing happens). Here is my code:
var doc = $(document); var hold_trigger = $('.qandacontent, tr[id^="comment-"], div[class] > p:not([class])'); hold_trigger.mousedown(function() { timeout_id = setTimeout(menu_toggle.bind(this), hold_time); }).bind('mouseup mouseleave', function() { clearTimeout(timeout_id); }); And here is my new code after some researches:
var doc = $(document); var hold_trigger = $('.qandacontent, tr[id^="comment-"], div[class] > p:not([class])'); doc.on("mousedown", hold_trigger, function() { timeout_id = setTimeout(menu_toggle.bind(this), hold_time); }).bind('mouseup mouseleave', function() { clearTimeout(timeout_id); }); But it throws this:
Uncaught TypeError: Cannot read property 'replace' of undefined at HTMLDocument.menu_toggle
Any idea how can I fix it?
And here is menu_toggle function:
function menu_toggle() { var curr_url = window.location.href.replace(/#.*$/, ""); if ( $(this).is("tr") ){ url_of_elem = curr_url + "#" + $(this).attr("id"); $(".elm_url > h3").html($(".elm_url > h3").text().replace(/بخش|پست/,"پیام")); } else { url_of_elem = curr_url + "#" + $(this).siblings("table[id]").attr("id").replace("table","post"); $(".elm_url > h3").html($(".elm_url > h3").text().replace(/بخش|پیام/,"پست")); } document.getElementById("elm_url_input").value = decodeURI(url_of_elem); hold_menu.fadeIn(100); document.getElementById("elm_url_input").select(); }
menu_togglefunction?menu_toggle. Can you provide more code or a jsfiddle? The snippets are not enough to get a clear sight on the issue