jquery-events

jQuery .on() method doesn't see new elements

限于喜欢 提交于 2019-11-26 16:04:12
问题 I'm getting a JSON element and building a list from its items like this: getTitles: function(data) { data = data || {}; var list = []; $.getJSON( '/titles', data, function(data) { $.each(data.data, function(key, val) { list.push( '<li><a href="'+ val.href +'">'+ val.title +'</a><span class="count">'+ val.count +'</span></li>' ) }); $('#title-items').html(list.join('')); } ); } And I'm binding click event for a elements like this: $('a').on('click', function(e) { alert('clicked'); e

jQuery watch for domElement changes?

一笑奈何 提交于 2019-11-26 15:49:57
问题 I have an ajax callback which injects html markup into a footer div. What I can't figure out is how to create a way to monitor the div for when it's contents change. Placing the layout logic I'm trying to create in the callback isn't an option as each method (callback and my layout div handler) shouldn't know about the other. Ideally I'd like to see some kind of event handler akin to $('#myDiv').ContentsChanged(function() {...}) or $('#myDiv').TriggerWhenContentExists( function() {...}) I

How to remove “onclick” with JQuery?

强颜欢笑 提交于 2019-11-26 15:20:25
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? glmxndr 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 (like "$") $('[id="a$id"]').prop('onclick',null).off('click'); <script src="https://ajax.googleapis.com/ajax

How to pass values arguments to modal.show() function in Bootstrap

删除回忆录丶 提交于 2019-11-26 12:44:33
问题 I have a page the shows a list of local cafes. When the user clicks on a certain cafe, a modal dialog is shown, that already has the \"cafe name\" pre-filled. The page contains many cafe names, and the form should contain the \"cafe name\" that he clicked on. Following is the list of cafe names generated as text with link button <table class=\"table table-condensed table-striped\"> <tbody> <tr> <td>B&Js </td> <td>10690 N De Anza Blvd </td> <td> <a class=\"btn btn-primary\" data-toggle=\"modal

jQuery get input value after keypress

故事扮演 提交于 2019-11-26 11:57:12
问题 I have the following function: $(document).ready(function() { $(\"#dSuggest\").keypress(function() { var dInput = $(\'input:text[name=dSuggest]\').val(); console.log(dInput); $(\".dDimension:contains(\'\" + dInput + \"\')\").css(\"display\",\"block\"); }); }); For some reason, for the first keypress, I\'m getting an empty string to the console log. 回答1: This is because keypress events are fired before the new character is added to the value of the element (so the first keypress event is fired

How to detect if the user clicked the “back” button

若如初见. 提交于 2019-11-26 11:13:44
问题 When the user goes history-back-1...how do I detect that? And then, alert \"the user clicked back!\" Using binds (and jQuery preferably) 回答1: You generally can't (browser security restriction). You can tell if the user navigates away from the page (onbeforeunload, onunload fire) but you can't tell where they went unless you've set up your page to allow it. HTML5 introduces the HTML5 History API; in conforming browsers, the onpopstate event will fire if the user navigates back to an earlier

Detect multiple keys on single keypress event in jQuery

被刻印的时光 ゝ 提交于 2019-11-26 08:50:40
问题 Is it at all possible to combine a mixture of keypress\' to fire a single event? $(document).keyup(function(e){ if (e.keyCode == 68 && e.keyCode == 69 && e.keyCode == 86) { alert(\'oh hai\'); } }); I\'ve tried it in Chrome but the event doesn\'t fire. Call me crazy but I am writing a Chrome extension and want to push D + E + V keys together to force it into a hidden developer mode. 回答1: If you want to detect that the d , e , and v keys were all down at the same time, you have to watch both

return false from jQuery click event

若如初见. 提交于 2019-11-26 07:26:04
问题 I have click events set up like this: $(\'.dialogLink\') .click(function () { dialog(this); return false; }); The all have a \"return false\" Can someone explain what this does and if it\'s needed? 回答1: When you return false from an event handler it prevents the default action for that event and stops the event bubbling up through the DOM. That is, it is the equivalent of doing this: $('.dialogLink') .click(function (event) { dialog(this); event.preventDefault(); event.stopPropagation(); });

HTML5 dragleave fired when hovering a child element

丶灬走出姿态 提交于 2019-11-26 06:11:17
问题 The problem I\'m having is that the dragleave event of an element is fired when hovering a child element of that element. Also, dragenter is not fired when hovering back the parent element again. I made a simplified fiddle: http://jsfiddle.net/pimvdb/HU6Mk/1/. HTML: <div id=\"drag\" draggable=\"true\">drag me</div> <hr> <div id=\"drop\"> drop here <p>child</p> parent </div> with the following JavaScript: $(\'#drop\').bind({ dragenter: function() { $(this).addClass(\'red\'); }, dragleave:

How to differentiate single click event and double click event?

℡╲_俬逩灬. 提交于 2019-11-26 05:49:40
问题 I have a single button in li with id \"my_id\" . I attached two jQuery events with this element 1. $(\"#my_id\").click(function() { alert(\'single click\'); }); 2. $(\"#my_id\").dblclick(function() { alert(\'double click\'); }); But every times it gives me the single click 回答1: You need to use a timeout to check if there is an another click after the first click. Here is the trick: // Author: Jacek Becela // Source: http://gist.github.com/399624 // License: MIT jQuery.fn.single_double_click =