javascript-events

Getting the class of the element that fired an event using JQuery

时间秒杀一切 提交于 2019-12-20 08:23:46
问题 is there anyway to get the class when click event is fired. My code as below, it only work for id but not class. $(document).ready(function() { $("a").click(function(event) { alert(event.target.id + " and " + event.target.class); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <body> <a href="#" id="kana1" class="konbo">click me 1</a> <a href="#" id="kana2" class="kinta">click me 2</a> </body> </html> jsfiddle code here 回答1: Try: $

Binding events to views - Firing uneven number of times

◇◆丶佛笑我妖孽 提交于 2019-12-20 07:41:34
问题 I have UserModel : UserView and UserCollection : UserCollectionView . With this, I am trying to bind a click event to the UserView (I am doing this in UserView ). So, this is the code I have: var root = 'http://localhost:5000/api/v1'; var app = {}; // Backbone Model app.UserModel = Backbone.Model.extend({ defaults: { // urlRoot: root + '/users', name: 'Default Name', email: '30', username: 'default_username' }, initialize: function() { this.set({ id: this.get('username') }); console.log('User

Javascript: how to stop the click event queuing?

心不动则不痛 提交于 2019-12-20 07:32:51
问题 The following code works fine the only problem is that the click event get queued like for example the setTimeout gets called for each click and the popup appears multiple times. How to make the popup appear only when user clicks and to ensure that gap between each popup is lets say 4 seconds var showpopup = 1; var check = true; var seconds = 4000; // change the frequency here current frequency = 2 seconds var url = "https://www.fb.com"; // change the url here var strWindowFeatures = "toolbar

Calling a server side function using a javascript

安稳与你 提交于 2019-12-20 07:28:15
问题 I need to invoke a server side function when an item is picked in an ASP drop-down box, Can someone please tell me how to do that? 回答1: Within ASP.NET use the drop down selected index change event. Alternatively for a client side event you could use JQuery and then use the following JavaScript function to contact the Server: function CallServer() { $.ajax({ url: 'webserviceURL', type: "POST", datatype: "json", success: function (result) { if (result.Success) { } else { } } }); } 回答2: set ddl

javascript event not triggered if the change origin is not from the html?

时间秒杀一切 提交于 2019-12-20 07:26:04
问题 I am trying to understand why the change event in the following example is not triggered (I'll show exactly where). I have a checkbox, lets call it 'mainCheckbox', when checked - I want to check some other related checkboxes (so far working). In addition when I uncheck one of the related checkboxes (child checkboxes) - I want to uncheck the mainChecbox, this also works - but here is something I am failing to understand: I am changing the checked property of the mainCheckbox (in the onchange

onmouseover fired before click and mouseout events?

依然范特西╮ 提交于 2019-12-20 07:17:54
问题 Unusable links with onmouseover() got an interesting question, when I tried to answer it. After some logging experiments, I've set up http://jsfiddle.net/RnGxP/1/. The last two examples work as expected, the hide when clicking on "Close" or leaving the "Close" div. The first two examples set a new innerHTML to the div whenever the mouse moves in it (I'd never do that myself, but...). So, when moving the mouse into one of them they get expanded. And moving the mouse further on a link or the

document.write in jsonp callback

£可爱£侵袭症+ 提交于 2019-12-20 05:53:25
问题 I am making a cross domain request using script tag hack and jsonp. In the callback function, I want to write the data received to DOM using document.write(). I know that I should use appendChild/innerHTML instead of doc.write(). My constraint is I do not have a class/id hook to the element I want to write to. I can only rely on document.write() to write "in place". Following code is included in HTML div in a script tag.: function request_jsonp(){ var script = document.createElement('script')

Can Javascript detect when an embedded Youtube video has ended?

好久不见. 提交于 2019-12-20 05:30:15
问题 I have a div containing a video. The background of the div features a fake "play" button, which I've designed to use as the play button instead of Youtube's standard video "play" button. The video is initially set to "display:none". I've deployed the code below so that when you click on the div, the div disappears and the video now displays and begins to play. How can I edit the code so that when the video has finished playing, the video disappears and the div re-appears? <div class="videodiv

Google Maps API, error with InfoWindow domready event handler

六月ゝ 毕业季﹏ 提交于 2019-12-20 05:20:17
问题 I'm setting up a form within an info info window for crowdsourcing location data. I've got everything up and running, but I'm trying to copy the lat and lng values into the form elements when the info window pops open. I've been successful with other event listener on the map div, but when I use the domready event handler for the info window I get an error: "Uncaught TypeError: Cannot read property '_ e3 ' of undefined." The issue seems to be within the domready event listener. // Global

Event Delegation Pattern with addEventListener and nested elements in buttons

假装没事ソ 提交于 2019-12-20 04:59:09
问题 I have a set of buttons in a parent. Each containing an SVG icon which are added programmatically. I'm attempting to listen on the parent element and then use event delegation to trigger different functionality for particular buttons, but what lands up happening is I get event targets of the contained svg's or paths rather than the buttons themselves. Is there a way to leverage event bubbling, or change the way I'm doing this to still avoid adding a ton of event handlers, and trigger the