jquery-on

jQuery event delegation in 1.7.2

為{幸葍}努か 提交于 2019-12-12 03:52:54
问题 Is there any way to delegate an event using jQuery that will correspond to all elements on the page that match the selector, other than delegating from $(document) ? Since that's probably poorly worded, here's the rub: There used to be jQuery.live that delegated events to all elements that matched the selector. This was superseded by jQuery.delegate which delegated events within a specific context selector to its children, which in turn was superseded by jQuery.on , which does effectively the

jQuery hover effect not working

六月ゝ 毕业季﹏ 提交于 2019-12-12 00:49:20
问题 I have dynamically generated div tags which looks something like this: <div class="widget widget_1"> <div class="widget_header widget_header_1"></div> <div class="widget_sub_header widget_sub_header_1"></div> <div class="widget_content widget_content_1"></div> <div class="widget_footer widget_footer_1"></div> <div> <div class="widget widget_1"> <div class="widget_header widget_header_1"></div> <div class="widget_sub_header widget_sub_header_1"></div> <div class="widget_content widget_content

Jquery not applying on dynamic elements created in context menu

帅比萌擦擦* 提交于 2019-12-11 12:19:34
问题 I have a script containing $('a').on('click', function () {alert($(this).attr('class')); }); In my contextmenu function, I create a list with links $(function () { $('a').on('contextmenu', function (event) { $("<ul id='menu'></ul>") .append('<li><a href="#" class="test">Test 1</a></li>') .append('<li><a href="">Test 2</a></li>') .appendTo("body") .css({ top: event.pageY + "px", left: event.pageX + "px" }); return false; }); }); However, the first piece of code (the on click event) does not

jQuery $.on.apply not working

依然范特西╮ 提交于 2019-12-11 07:12:09
问题 Any one know why $.on.apply(this, args); gives me "Uncaught TypeError: Cannot read property 'apply' of undefined" I know for sure that $.on is defined in jQuery :/ 回答1: The on() method is bound to $.fn $ $.fn.on.apply(this, args); 回答2: I think your syntax is incorrect. use syntax like $('el').on("click", function() { alert( $( this ).text() ); }); 回答3: You know for sure $.on is defined, well... I beg to differ: console.log($.on);//undefined console.log($.fn.on);//function (a,c,d,e,f) console

jQuery append and binding click event using on

穿精又带淫゛_ 提交于 2019-12-11 02:17:15
问题 I am attempting to create a table row with a button in it that when clicked creates a new table row. The new row also has the same "add line" button on it and I would like to be able to click that button to add another row. But I cannot seem to get the click event to bind to an element that is appended within the click event. I am sure I am using "on" incorrectly but I can't seem to figure out how to do this. http://jsfiddle.net/vivojack/WkfvC/2/ my (simplified) html <table id="ct"> <tbody>

Is there a way to unbind a delegated event on each element instance?

天大地大妈咪最大 提交于 2019-12-10 23:42:39
问题 What I need to do is get the functionality of jQuery.one on each matched element using delegation. As you can see clicking on the link for "Baz" or "Bat" appends "(removed)" multiple times. On the other hand clicking the link for "Foo" executes the code only once, but then also disables it for "Bar" (or vice versa). Fiddle: http://jsfiddle.net/JcmpN/ What i want to happen is that clicking on any of these executes the handler for that element, but leaves the others intact until they are also

jQuery how to translate livequery to on?

本秂侑毒 提交于 2019-12-08 06:11:47
问题 I have this code which works however it is using a old legacy function "livequery" which should really be switched to using "on". However for the life of me I can't get this to work. Here is my code snippet. jQuery('.box').livequery(function(){ jQuery('a', this).click(function() { return false; }); jQuery(this).draggable({ appendTo: "body", helper: 'clone', opacity: 0.5, zIndex: 900, stop: function(event, ui) { return true; } }); }); And I tried this... jQuery('.box').on('draggable', function

How to call a function in every element in the DOM even if they are dynamically created

六月ゝ 毕业季﹏ 提交于 2019-12-08 00:48:02
问题 I want to call a function over specific elements on my DOM, for example: $(".red").css({backgroundColor: "pink"}); It works ok for any element already existing into the DOM, but I also want to this method to be called in elements dynamically added to the DOM. I've tried things like: $(".red").on(function(){ this.css({backgroundColor: "pink"}) }); or: $(".red").on("load", function(){ this.css({backgroundColor: "pink"}) }); But not any success. Check the jsFiddle Update The .css() call is just

jQuery .on keyup and blur firing onload only

一个人想着一个人 提交于 2019-12-03 13:18:54
问题 Problem: The blur and keyup events each fire once onload, and only onload. How can I get them to work correctly? jQuery: function myFunction(text){ alert(text); } $('#input1').on({ keyup: myFunction('keyup'), blur: myFunction('blur'), focus: function(){console.log('focus!');} }); Fiddle: http://jsfiddle.net/GrMQX/ 回答1: You are not assigning a function to keyup and blur , you're assigning the result of the execution of myFunction . Change it like this: $('#input1').on({ keyup: function() {

jQuery on('hover') Event Replacement

一个人想着一个人 提交于 2019-12-02 10:06:59
问题 I'm looking to swap an img src on hover. Typically I would use: $('#img').hover(function() { $(this).attr('src', 'http://www.example.com/new-img.jpg'); }); However, I'm loading the content in via Ajax so normally I would use: $('#main').on('hover', '#img', function() { $('#img').attr('src', 'http://www.example.com/new-img.jpg'); }); But I'm reading that on('hover', ...) was deprecated in jQuery 1.8 and removed in 1.9 (jQuery Docs), which is what I'm currently using. Do anyone have any work