jquery-events

How to monitor when the body 'data' attribute changes in jQuery?

喜你入骨 提交于 2019-12-01 19:45:40
I have data-segment attribute in my body tag that is changed by a slider. I need to trigger a function based on the value of this, when it is changed. I'm not sure how to attach an event listener in this case though? `There is no reliable cross-browser way to receive an event when a DOM node attribute is changed. Some browsers support "DOM mutation events", but you shouldn't rely on them, and you may Google that phrase to learn about the ill-fated history of that technology. If the slider control does not fire a custom event (I would think most modern ones do), then your best bet is to set up

Twitter bootstrap typeahead unable to add to dynamically created element

我只是一个虾纸丫 提交于 2019-12-01 19:18:53
Is there a way to convert twitter bootstrap's typeahead function into a $("body").on() function? The following code works fine if the element exists on the page load. $("#job_title").typeahead({ source: searchFunction, onselect: function(obj) { } }); But if I add the text input with id="job_title" dynamically, the above function doesn't work. Is there a workaround for this? Dustin L. This solution requires no additional javascript. From https://stackoverflow.com/a/15094730 $("#element-that-will-contain-typeaheads").on("DOMNodeInserted", function () { $(this).find(".typeahead").typeahead(); });

Twitter bootstrap typeahead unable to add to dynamically created element

别来无恙 提交于 2019-12-01 17:54:28
问题 Is there a way to convert twitter bootstrap's typeahead function into a $("body").on() function? The following code works fine if the element exists on the page load. $("#job_title").typeahead({ source: searchFunction, onselect: function(obj) { } }); But if I add the text input with id="job_title" dynamically, the above function doesn't work. Is there a workaround for this? 回答1: This solution requires no additional javascript. From https://stackoverflow.com/a/15094730 $("#element-that-will

jQuery event listener for when text has changed in a <td> cell?

送分小仙女□ 提交于 2019-12-01 17:02:12
问题 Is there any way in jQuery to attach a listener to a <td> cell so that when the text inside the cell has changed (by JavaScript, not the user), the event is triggered? 回答1: To extend mway's answer, here is some code. var td = $('#my-table tr td:eq(1)'); var tdHtml = td.html(); setInterval(function() { if (td.html() !== tdHtml) { // it has changed tdHtml = td.html(); } }, 500); ... and for his second suggestion. function updateTd(html) { $('#my-table tr td:eq(1)').html(html); // additional

Populate one dropdown list based on another dropdown list

为君一笑 提交于 2019-12-01 08:30:18
I have two dropdown menus as follows: <form id="dynamicForm"> <select id="A"> </select> <select id="B"> </select> </form> And I have a dictionary object where the keys are the options for A and the values, B are arrays corresponding to each element in A , as follows: var diction = { A1: ["B1", "B2", "B3"], A2: ["B4", "B5", "B6"] } How can I dynamically populate the menu B based on what the user selects in menu A? Bind a change event handler and populate second select tag based on selected value. var diction = { A1: ["B1", "B2", "B3"], A2: ["B4", "B5", "B6"] } // bind change event handler $('#A

Populate one dropdown list based on another dropdown list

不想你离开。 提交于 2019-12-01 06:22:26
问题 I have two dropdown menus as follows: <form id="dynamicForm"> <select id="A"> </select> <select id="B"> </select> </form> And I have a dictionary object where the keys are the options for A and the values, B are arrays corresponding to each element in A , as follows: var diction = { A1: ["B1", "B2", "B3"], A2: ["B4", "B5", "B6"] } How can I dynamically populate the menu B based on what the user selects in menu A? 回答1: Bind a change event handler and populate second select tag based on

How to set the input value in a modal dialogue?

纵然是瞬间 提交于 2019-12-01 03:29:01
I'm working on 'add a link' functionality. For that I'm using Modal plugin from Twitter Boostrap JS . On the main page there's only the 'link' field to fill, when a user clicks 'add link' button, a modal pops up, and the user sees the complete form to fill 3 fields: link, title, tags. However, I want the link field to be pre-filled with the value from the previous step. It's similar to what happens when you 'save a link' on delicious.com. Thanks to Joe's help ( previous question ) I can print the linkURL on the modal dialogue, but it's important that this linkURL is the value of the link field

Detect if a scroll event is triggered manually in jQuery

懵懂的女人 提交于 2019-12-01 03:24:34
This question was already asked here a long time ago: Detect jquery event trigger by user or call by code But it has never been answered conclusively (or maybe I'm simply not able to search properly). Is it possible to detect whether a scroll event has been triggered by the user or by the jQuery animate function? I am trying to prevent the scroll event to trigger itself while doing something like this: $(document).scroll(function(){ $("html").stop(true); var number = 400; //some other stuff is happening here clearTimeout(tout); tout = setTimeout(function(){ if(top == $(document).scrollTop()){

How to set the input value in a modal dialogue?

只愿长相守 提交于 2019-12-01 00:12:33
问题 I'm working on 'add a link' functionality. For that I'm using Modal plugin from Twitter Boostrap JS. On the main page there's only the 'link' field to fill, when a user clicks 'add link' button, a modal pops up, and the user sees the complete form to fill 3 fields: link, title, tags. However, I want the link field to be pre-filled with the value from the previous step. It's similar to what happens when you 'save a link' on delicious.com. Thanks to Joe's help (previous question) I can print

Is there an opposite function of preventDefault() in JavaScript?

给你一囗甜甜゛ 提交于 2019-11-30 17:09:09
I am counting words in a text field and after a certain amount of words, I use prevent default. In the else, I would like to re-enable the default commands. Does preventDefault( ) have an opposite function? Here is some sample code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>preventDefault</title> <style type="text/css"></style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text