jquery-events

How to bind Events on Ajax loaded Content?

倖福魔咒の 提交于 2019-11-26 04:36:44
问题 I have a link, myLink , that should insert AJAX-loaded content into a div (appendedContainer) of my HTML page. The problem is that the click event I have bound with jQuery is not being executed on the newly loaded content which is inserted into the appendedContainer. The click event is bound on DOM elements that are not loaded with my AJAX function. What do I have to change, such that the event will be bound? My HTML: <a class=\"LoadFromAjax\" href=\"someurl\">Load Ajax</a> <div class=\

How to remove “onclick” with JQuery?

本小妞迷上赌 提交于 2019-11-26 04:21:37
问题 PHP code: <a id=\"a$id\" onclick=\"check($id,1)\" href=\"javascript:void(0)\" class=\"black\">Qualify</a> I want to remove the onclick=\"check($id,1) so the link cannot be clicked or \" check($id,1) won\'t be fired. How can I do it with JQuery? 回答1: Old Way (pre-1.7): $("...").attr("onclick", "").unbind("click"); New Way (1.7+): $("...").prop("onclick", null).off("click"); (Replace ... with the selector you need.) // use the "[attr=value]" syntax to avoid syntax errors with special characters

How to detect escape key press with pure JS or jQuery?

纵饮孤独 提交于 2019-11-26 03:01:42
问题 Possible Duplicate: Which keycode for escape key with jQuery How to detect escape key press in IE, Firefox and Chrome? Below code works in IE and alerts 27 , but in Firefox it alerts 0 $(\'body\').keypress(function(e){ alert(e.which); if(e.which == 27){ // Close my modal window } }); 回答1: Note: keyCode is getting deprecated use key instead. function keyPress (e) { if(e.key === "Escape") { // write your logic here. } } Here is jsfiddle keyCode is Getting deprecated It seems keydown and keyup

keypress, ctrl+c (or some combo like that)

主宰稳场 提交于 2019-11-26 02:56:32
问题 I\'m trying to create shortcuts on the website I\'m making. I know I can do it this way: if(e.which == 17) isCtrl=true; if(e.which == 83 && isCtrl == true) { alert(\'CTRL+S COMBO WAS PRESSED!\') //run code for CTRL+S -- ie, save! e.preventDefault(); } But the example below is easier and less code, but it\'s not a combo keypress event: $(document).keypress(\"c\",function() { alert(\"Just C was pressed..\"); }); So I want to know if by using this second example, I could do something like: $

How to detect online/offline event cross-browser?

让人想犯罪 __ 提交于 2019-11-26 00:58:52
问题 I\'m trying to accurately detect when the browser goes offline, using the HTML5 online and offline events. Here\'s my code: <script> // FIREFOX $(window).bind(\"online\", applicationBackOnline); $(window).bind(\"offline\", applicationOffline); //IE window.onload = function() { document.body.ononline = IeConnectionEvent; document.body.onoffline = IeConnectionEvent; } </script> It works fine when I just hit \"Work offline\" on either Firefox or IE, but it\'s kind of randomly working when I

Long Press in JavaScript?

守給你的承諾、 提交于 2019-11-26 00:57:38
问题 Is it possible to implement \"long press\" in JavaScript (or jQuery)? How? (source: androinica.com) HTML <a href=\"\" title=\"\">Long press</a> JavaScript $(\"a\").mouseup(function(){ // Clear timeout return false; }).mousedown(function(){ // Set timeout return false; }); 回答1: There is no 'jQuery' magic, just JavaScript timers. var pressTimer; $("a").mouseup(function(){ clearTimeout(pressTimer); // Clear timeout return false; }).mousedown(function(){ // Set timeout pressTimer = window

Getting value of select (dropdown) before change

余生长醉 提交于 2019-11-26 00:09:43
问题 The thing I want to achieve is whenever the <select> dropdown is changed I want the value of the dropdown before change. I am using 1.3.2 version of jQuery and using on change event but the value I am getting over there is after change. <select name=\"test\"> <option value=\"stack\">Stack</option> <option value=\"overflow\">Overflow</option> <option value=\"my\">My</option> <option value=\"question\">Question</option> </select> Lets say currently option My is selected now when I change it to

Long Press in JavaScript?

[亡魂溺海] 提交于 2019-11-26 00:06:58
Is it possible to implement "long press" in JavaScript (or jQuery)? How? (source: androinica.com ) HTML <a href="" title="">Long press</a> JavaScript $("a").mouseup(function(){ // Clear timeout return false; }).mousedown(function(){ // Set timeout return false; }); Diodeus - James MacFarlane There is no 'jQuery' magic, just JavaScript timers. var pressTimer; $("a").mouseup(function(){ clearTimeout(pressTimer); // Clear timeout return false; }).mousedown(function(){ // Set timeout pressTimer = window.setTimeout(function() { ... Your Code ...},1000); return false; }); Based on Maycow Moura's

jQuery.click() vs onClick

[亡魂溺海] 提交于 2019-11-25 23:57:09
问题 I have a huge jQuery application, and I\'m using the below two methods for click events. First method HTML <div id=\"myDiv\">Some Content</div> jQuery $(\'#myDiv\').click(function(){ //Some code }); Second method HTML <div id=\"myDiv\" onClick=\"divFunction()\">Some Content</div> JavaScript function call function divFunction(){ //Some code } I use either the first or second method in my application. Which one is better? Better for performance? And standard? 回答1: Using $('#myDiv').click

jQuery click events firing multiple times

吃可爱长大的小学妹 提交于 2019-11-25 23:45:57
问题 I\'m attempting to write a video poker game in Javascript as a way of getting the basics of it down, and I\'ve run into a problem where the jQuery click event handlers are firing multiple times. They\'re attached to buttons for placing a bet, and it works fine for placing a bet on the first hand during a game (firing only once); but in betting for the second hand, it fires the click event twice each time a bet or place bet button is pressed (so twice the correct amount is bet for each press).