jquery-on

mousedown event on options in select with jquery .on

Deadly 提交于 2021-01-28 11:47:52
问题 I was reading the documentation of the .on event handler of jQuery and I started playing around with it. I have a simple <select> element with the multiple attribute set to true. However, I want the user to be able to select multiple items without having to press the ctrl or shift key(s) According to the .on documentation, if you specify a selector it will automatically add those event handlers to any new items added inside that container that match the selector specified. So in my case, I

jQuery - How to make .on event work for dynamically created HTML?

旧时模样 提交于 2020-02-02 15:33:06
问题 Reading up on the New specs for the newest jQuery 1.x library, it says to use .on to attach events that work for dynamically created jQuery elements, however, I can't seem to get this work at all. In my $(document).ready function I have the following: jQuery: $(".dropdown").on("click", function(event) { event.preventDefault(); var type = $(this).text() == '[ Read more... ]' ? 'expand' : 'collapse'; var theDiv = type == 'expand' ? $(this).parent().next("div") : $(this).parent().prev("div");

jquery on function and document ready

China☆狼群 提交于 2020-01-05 09:14:59
问题 I use the jQuery on() function to attach an onclick function to a set of anchors in my website as follows: <ul> <li>First <a href='#' title='delete' class="itemDelete">x</a></li> <li>Second <a href='http://www.repubblica.it' title='delete' class="itemDelete">x</a></li> <li>Third <a href='#' title='delete' class="itemDelete">x</a></li> </ul>​ <script type="text/javascript"> $(document).on('click', '.itemDelete', function(e) { $(this).closest('li').remove(); e.preventDefault(); }); </script>

Bind multiple events to same function

强颜欢笑 提交于 2020-01-04 13:05:27
问题 How can I bind mutiple events to the same function. I want click and touchstart to do the same. And then I want a second function for mouseover. I would like to use this kind of setup: $(document).on({ click: function (event) { // I want this: click, touchstart: function (event) { event.preventDefault(); // do something }, mouseover: function (event) { event.preventDefault(); // do something } }, '.link'); 回答1: You can combine the events in one .on() with space: $(document).on('click

Do I need to unbind jquery event before remove element?

旧街凉风 提交于 2019-12-29 18:20:46
问题 I have a page using jquery-ui-dialog. Each time the dialog opens, page contents load in using ajax. Then it binds some event using jquery "on()". When the dialog close, it will empty its content. The question is , do I need to unbind the events on ".ajax-content" before $.empty()? edit : concern 1. any possible degrade JS performance? if I empty() hundreds of nodes this way. concern 2. would remove element also remove events from memory(or whatever execution/evaluation chain of jquery)? I am

Do I need to unbind jquery event before remove element?

不打扰是莪最后的温柔 提交于 2019-12-29 18:20:08
问题 I have a page using jquery-ui-dialog. Each time the dialog opens, page contents load in using ajax. Then it binds some event using jquery "on()". When the dialog close, it will empty its content. The question is , do I need to unbind the events on ".ajax-content" before $.empty()? edit : concern 1. any possible degrade JS performance? if I empty() hundreds of nodes this way. concern 2. would remove element also remove events from memory(or whatever execution/evaluation chain of jquery)? I am

jquery .on() pass data through function

纵然是瞬间 提交于 2019-12-24 03:07:26
问题 I am reading the .on() jquery documentation. And is it possible to pass some data like this: function greet( event ) { alert( "Hello " + event.data.name ); } $( "button" ).on( "click", {name: "Karl"}, greet ); The prototype of the methos is: $(selector).on(event,childSelector,data,function,map) Is it possible to have a more complex thin instead of only a string into the data parameter?. In my case: I will be generating dynamically some popups with a number input inside and some text. Is it

jquery .on() pass data through function

我的梦境 提交于 2019-12-24 03:07:00
问题 I am reading the .on() jquery documentation. And is it possible to pass some data like this: function greet( event ) { alert( "Hello " + event.data.name ); } $( "button" ).on( "click", {name: "Karl"}, greet ); The prototype of the methos is: $(selector).on(event,childSelector,data,function,map) Is it possible to have a more complex thin instead of only a string into the data parameter?. In my case: I will be generating dynamically some popups with a number input inside and some text. Is it

can't remove specific event handlers when attached to document with .on()

巧了我就是萌 提交于 2019-12-12 11:21:17
问题 Here's a simple fiddle to demo my situation... http://jsfiddle.net/UnsungHero97/EM6mR/17/ What I'm doing is adding an event handler for current & future elements, using .on() . I want to be able to remove these event handlers for specific elements when something happens; in the case of the fiddle, when the radio button is selected, the event handler for the blue elements should be removed and clicking those elements should not do anything anymore. It doesn't seem to be working :( How do I

Method of object as handler

*爱你&永不变心* 提交于 2019-12-12 04:53:14
问题 I try this: function MovableLine (line, number) { this.line = line; this.number = number; } MovableLine.prototype.start = function (e) { alert(this.number); alert(this); }; and then: var mline = this.xAxis[0].plotLinesAndBands[plotLinesCount].svgElem; mline.css({ 'cursor': 'pointer' }); mline.translate(0, 0); movableLine = new MovableLine(mline, 10); movableLine.line.on('mousedown', movableLines[plotLinesCount].start); result: first alert: undefined second alert: object SWGPathElement How to