javascript-events

How to remove an element that is added dynamically in javascript

夙愿已清 提交于 2019-12-30 00:32:28
问题 I have the following code to create some element <div id="parent"> <div id="block_1" > <div> <input type="text"> </div> <img src="arrow.jpg"> <div> <input type="text"> </div> <div><a href="#" class="remove_block">Remove</a></div> </div> </div> the result look like this When user presses the ADD button it will go to a javascript function and create the same block of div. Here is the code function add_block() { var curDiv = $('#parent'); var i = $('#parent div').size()/4 + 1; var newDiv='<div

add or subtract functions from onSubmit event handler?

假如想象 提交于 2019-12-29 09:02:11
问题 I have the following code: function showAddrBox() { var prompt = document.getElementById('addr_prompt'); prompt.style.display = 'block'; document.generic_form.address.style.display = 'block'; document.generic_form.onsubmit = validateAddrForm; } function hideAddrBox() { var prompt = document.getElementById('addr_prompt'); prompt.style.display = 'none'; document.generic_form.address.style.display = 'none'; document.generic_form.onsubmit = null; } The problem is that sometimes I have additional

How can I remove an inline onclick attribute with a bookmarklet?

眉间皱痕 提交于 2019-12-29 08:56:17
问题 There is an annoying website out there that foils attempts to "open in new tab" by using <div onclick=> instead of <a href=> . I've written a bookmarklet, using jQuery, that creates a wrapper <a> tag and inserts it within the <div> around its content. How can I remove the original onclick handler? 回答1: Not mentioned yet: $('#myId')[0].onclick = null; // remove the inline onclick() event 回答2: Untested, but... $("selector").removeAttr("onclick"); I guess you have already tried to $("selector")

How to capture the click event on the default print menu called by Javascript window.print()?

主宰稳场 提交于 2019-12-29 08:33:09
问题 I have built a page that is print-enabled using window.print(). Because of some really unusual requirements from management, I need to be able to capture the click event for the print menu that appears when window.print() is called. Specifically, in Chrome, I need to capture the click event for the 'Print' (blue) and 'Cancel' (gray) buttons. I have to admit I don't even know where to start here. I inspected each element and can see that these are standard html elements. These buttons have

Maximum call stack size exceeded on trigger click [duplicate]

谁都会走 提交于 2019-12-29 08:29:09
问题 This question already has answers here : Triggering click event inside my .click callback causes “Maximum call stack size exceeded” (4 answers) Closed 3 years ago . I really want to do something simple. On click on a certain element, i trigger a click on another element but i get the below error on my console. Uncaught RangeError: Maximum call stack size exceeded My code is as below; $('body').on('click', '.actual-click-element', function(event) { $('.trigger-click-element').trigger('click');

how do I detect if window.location failed?

烂漫一生 提交于 2019-12-29 06:53:10
问题 how do I check if a call to window.location failed because the given URL was invalid, etc? Is there some event I can set on the window object or on some other object that can catch this? 回答1: Finally got it to work using a "workaround" that is not a generic solution as I originally hoped: I am using the fact that the link I am trying to open is a custom url scheme (e.g. myxx://localhost) on mobile, and if it fails, the action I want to perform is a redirection to a standard appstore URL (os

In HTML, with Javascript, create new radio button and its text?

房东的猫 提交于 2019-12-29 06:31:35
问题 I want that when the "Yes" radio button of a form (form1) is checked, a new form (form2) appears, with two radio buttons and their text "Yes" and "No". With an event "onclick" in the "Yes" button of the form1, I manage to make the new form appear, with the two radio buttons, but I cannot make their text appear. Since radio buttons do not have "innerHTML", I try to add the text either as plain text, either as "label", but it is not working. Is it a problem in the syntax or in the logic (not

Handling 'ctrl+s' keypress event for browser

十年热恋 提交于 2019-12-29 05:26:06
问题 I was trying to implement the CTRL + S feature for a browser based application.I made a search and came across 2 scripts in the following to questions Best cross-browser method to capture CTRL+S with JQuery? Ctrl+S preventDefault in Chrome However,when I tried to implement it,it worked but,I still get the default browser save dialog box/window . My Code:For shortcut.js shortcut.add("Ctrl+S",function() { alert("Hi there!"); }, { 'type':'keydown', 'propagate':false, 'target':document }); jquery

-webkit-tap-highlight-color: rgba(0,0,0,0); on a div?

空扰寡人 提交于 2019-12-29 04:45:10
问题 Is there any way to apply this to a div? 回答1: Are you writing for iPhone/Smartphone websites? If so, then yes. But you'll probably only see the results on your phone/simulator. I think that this element can only be used on links or javascript elements. The div would have to be affected by some kind of scripting, or be a link. https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html <!DOCTYPE HTML>

How to limit handling of event to once per X seconds with jQuery / javascript?

筅森魡賤 提交于 2019-12-29 04:26:06
问题 For a rapidly-firing keypress event, I want to limit the handling of the event to a maximum of once per X seconds. I'm already using jQuery for the event handling, so a jQuery-based solution would be preferred, though vanilla javascript is fine too. This jsfiddle shows keypress firing rapidly without any limiting on the handling This jsfiddle implements limiting the handling to once per 0.5 seconds in vanilla JS using setTimeout() My question is Does jQuery have an inbuilt way of doing this?