jquery-events

Compare 'e.target' to a jQuery object

放肆的年华 提交于 2020-02-19 07:58:06
问题 What I want to do: ( clickedObject === someDiv ) //returns true or false What I tried ( $(e.target) === $('.selector') ); //returns a false negative. My workaround ( $(e.target).attr('class') === $('.selector').attr('class') ); //works as intended, not so clean though. What is the right way to compare the object I clicked to an object in the DOM? 回答1: To check if e.target has this class you can use the hasClass function. if ($(e.target).hasClass("selector")) Or, if you really want to compare

Creating a tag using jQuery bootstrap-tagsinput without hitting the enter key [closed]

寵の児 提交于 2020-02-05 03:57:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 months ago . I'm using jquery bootstrap-tagsinput and currently the only method for creating a tag is by hitting the enter key after typing it in. What I am looking for is a more easy user method of creating the tags. I was thinking that I could do an onblur somewhere in the bootstrap-tagsinput.js file. Can someone assist?

How do you switch between two texts in one jQuery call?

痞子三分冷 提交于 2020-01-30 06:06:07
问题 Let's say you have a .click() call. What code could you write inside of that .click() call so that each time you click the selected element, you change the text between two strings. I'm assuming .toggle() and .text() would play a role here... 回答1: Try this: $('#someElement').toggle(function(){ $(this).text('text1'); }, function(){ $(this).text('text2'); } ); 回答2: Try something along these lines: $element.bind('click', function() { $(this).html($(this).html() == 'string1' ? 'string2' :

Detect Close windows event by jQuery

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-18 04:57:08
问题 Could you please give me the best way to detect only window close event for all browsers by jQuery? I mean clicking X button on the browser or window.close() , not meaning F5 , form submission, window.location or link. I was looking for many threads but have not found the right way yet. 回答1: There is no specific event for capturing browser close event. You can only capture on unload of the current page. By this method, it will be effected while refreshing / navigating the current page. Even

How to trigger an event after using event.preventDefault()

不问归期 提交于 2020-01-18 03:45:49
问题 I want to hold an event until I am ready to fire it e.g $('.button').live('click', function(e){ e.preventDefault(); // do lots of stuff e.run() //this proceeds with the normal event } Is there an equivalent to the run() function described above? 回答1: Nope. Once the event has been canceled, it is canceled. You can re-fire the event later on though, using a flag to determine whether your custom code has already run or not - such as this (please ignore the blatant namespace pollution): var lots

How to trigger an event after using event.preventDefault()

非 Y 不嫁゛ 提交于 2020-01-18 03:45:26
问题 I want to hold an event until I am ready to fire it e.g $('.button').live('click', function(e){ e.preventDefault(); // do lots of stuff e.run() //this proceeds with the normal event } Is there an equivalent to the run() function described above? 回答1: Nope. Once the event has been canceled, it is canceled. You can re-fire the event later on though, using a flag to determine whether your custom code has already run or not - such as this (please ignore the blatant namespace pollution): var lots

Dynamically loading a script changes its behaviour

烂漫一生 提交于 2020-01-16 05:31:10
问题 I wanted paperjs to load after a button is pressed to turn on animations but it seems the paperscript doesn't work if paper is loaded after page load. If you comment out the setTimeout and uncomment the direct $.getScript - paperjs will fire the alert('hi') . I don't get it. <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function () { var paperUrl = 'http://cdnjs.cloudflare.com/ajax/libs/paper.js/0.22/paper.js'; $("#jq").text("jQuery

How to prevent jQuery hover event from firing when not complete?

喜夏-厌秋 提交于 2020-01-15 08:48:18
问题 Here is where I am having difficulty: $('div.sidebar_content_con').hover(function () { $(this).children('.sidebar_details_container').slideDown(500, function() { $(this).children('.sidebar_details, .sidebar_click').fadeIn(500); }); },function(){ $(this).children('.sidebar_details_container').slideUp(500) $('.sidebar_details, .sidebar_click').fadeOut(500); }); The problem is that multiple hover events can fire while the slideDown and fadeIn animations are occurring. Ideally, only one hover

How can I catch touchmove events on an element that is added to the DOM after my finger is already on the screen?

半城伤御伤魂 提交于 2020-01-13 09:21:12
问题 I am working on a Javascript / html5 project for iPad. I need to be able to catch touchmove events on an element that does not get added to the DOM until after a touchstart event has fired (i.e. until after a person has put their finger on the screen.) I have tried simulating a touchstart event and firing it programatically... $( "#container" ).append( element ); element.on( "touchmove", doStuff ); var ev = $.Event( "touchstart" ); element.trigger( ev ); ...however this does not work. The

Cancel click event in the mouseup event handler

自古美人都是妖i 提交于 2020-01-10 00:27:11
问题 Writing some drag&drop code, I'd like to cancel the click events in my mouseup handler. I figured preventing default should do the trick, but the click event is still fired. Is there a way to do this? This doesn't work: <div id="test">test</div> <script> $("#test").mouseup (function (e) { var a = 1; e.preventDefault(); }); $("#test").click (function (e) { var a = 2; }); 回答1: I had the same problem and didn't found a solution either. But I came up with a hack that seems to work. Since the