w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Multiple event listeners (with SSCCE)
I made a simple modification to the Menu class as follows: public class Menu implements ActionListener { ... public Menu(boolean blocked) { // this.blocked = blocked; ... startButton = createGUIButton("Resume game"); stopButton = createGUIButton("Exit game"); panel.add(startButton); panel.add(stopButton); // contentPane.add(panel); // menuWindow.validate(); blockActionListeners(blocked); // added this line } ... public void blockActionEvents(boolean blocked) { this.blocked = blocked; if (blocked) { // added from here... contentPane.remove(panel); menuWindow.validate(); } else { contentPane.add(panel);

Categories : Java

Multiple different event listeners in for loop
This is asked frequently. JavaScript doesn't have block scope. Variable scope is only created when you invoke a function. So to scope your i to the current loop iteration, you need to reference it in a function invocation that also creates the handler. // Create a function that returns a function function createHandler(i) { // The value of `i` is local to this variable scope // Return your handler function, which accesses the scoped `i` variable return function() { alert(array[i]); } } var array = ["Hey", "Hi", "Hello"]; for (var i = 0; i < array.length; i++) { var box = document.createElement("div"); box.className = "box"; // Invoke the `createHandler`, and pass it the value that needs to be scoped. // The returned function will use its reference

Categories : Javascript

Registering multiple event listeners even though I'm using removeEventListener
addEventListener does not return a value, so handler is undefined and the call to removeEventListener will fail. Use a named function expression instead: // give the function a name vvvvvvv e.target.addEventListener('mouseout', function handler(d) { // ... this.removeEventListener('mouseout', handler, false); // use name }, false); // <- don't forget `false` here, just in case The name of the function is only accessible inside the function itself.

Categories : Javascript

How to add multiple listeners in jQuery/javascript?
You need a closure new scope : for (key in this.mybutton) (function(button) { $(button).click(function() { console.log("click:" + button) }); })(this.mybutton[key]); } or just use this: $(button).click(function() { console.log("click:" + this) }); Concatenating a DOM element and a string in the console log doesn't seem like a very good idea ?

Categories : Javascript

Javascript/html5 play multiple audio files or overlap audio
Howler.js provides a good library for firing off cross-browser sound sprites for games, should do the trick!

Categories : Javascript

JQuery: Bind multiple triggers from multiple elements to one event
You can check if an animation is currently running by using: function toggleSearch() { if (!$("#search").is(":animated")) { $("#search").animate({ width: "toggle", opacity: "toggle" }, "slow",function() { $(this).focus(); }); } } $("#searchButton").parent('li').siblings().animate({ width: "toggle", opacity: "toggle" }, "slow"); $("#searchButton").click(toggleSearch); $("#search").blur(toggleSearch); http://jsfiddle.net/hGgc9/3/

Categories : Jquery

Multiple charts with event listeners - how to find which chart has fired the listener? Test case and screenshot are attached
As far as I can tell, you are very nearly there with Update 2. Try : google.visualization.events.addListener(chart, 'select', (function(c) { return function() { alert(c); }; })(csv));

Categories : Javascript

How to remove event from multiple elements
Well, one reason might be that your loop never runs. You need to initialize i in your loop: for(var i = 0; i < inputs.length; i++){ var input = inputs[i]; input.removeEventListener('onmouseup'); } Otherwise this loop will never run due to i having the initial value of undefined. Your call to removeEventListener also won't work as expected. You will also need to provide a reference to the listener/handler that you used. See here for the proper usage of removeEventListener. If everything is using mouseUpFun, you can provide that to removeEventListener: input.removeEventListener('onmouseup', mouseUpFun);

Categories : Javascript

does javascript remove event listeners?
Inline CSS takes precedence over stylesheets. Once you click on a link, it will set the background-color property for all links, hence all links will not change color when you hover over it. A better alternative than hard-coding the style in your elements, you can try adding a CSS class to your links (like page-active) and style those elements as needed. Yet another alternative that saves you from clearing old classes is adding a class or ID to the page and use that to hide/show links as needed. <style> nav > a { display: none; } #page-about nav > a#link-home { display: inline-block; } <body id="page-about"> <nav> <a href="?tab=home" id="link-home">Home</a> <a href="?tab=about" id="link-about">About</a> <

Categories : Javascript

Is it possible to create javascript audio player with multiple tracks playing in same time?
It is possible with HTML5 Audio API. See this getting started tutorial: http://www.html5rocks.com/en/tutorials/webaudio/intro/ Here is an excellent library to start with: http://www.createjs.com and some examples: http://www.createjs.com/#!/SoundJS/demos as well as the official spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html

Categories : Javascript

How do I bind an event to an elements pageshow when there are multiple pages?
Page events should be bound like this: $(document).on("pageshow", "#page2" ,function(toPage, ui) { console.log($(this)); console.log(toPage); }); Working example: http://jsfiddle.net/qvZst/ But if you want to do something when page2 is available for the first time then you need to use page event called pagebeforecreate $(document).on("pagebeforecreate", "#page2" ,function() { console.log($(this)); console.log(toPage); }); Unfortunately pagebeforecreate don't have a toPage because it is a page that is about to be loaded. pagebeforeshow can also be used because it will trigger before page is shown and you can use it to access previous page data. To find out more about page events and their order take a look at my blog ARTICLE. There's also another solution, you can also

Categories : Jquery

Javascript: Errors arent being displayed on event listeners
Backbone invokes event handlers synchronously and doesn't catch handler exceptions. So if you had code that looked like: el.trigger('change:one'); // handler will throw exception el.trigger('change:two'); // won't execute The change:two event will never get triggered, resulting in your change:two handler never getting invoked.

Categories : Javascript

HTML5 Canvas Event Listeners and JavaScript - addEventListener("click")
Just a suggestion, but try moving the definition for of() before that of click(). The order of functions is not always significant in JS, but I think it may be for prototypes. I may be wrong (I haven't checked) but it will only take a moment to test.

Categories : Javascript

What is a proper way to add listeners to new elements after using AJAX to get the html content? (jQuery, Javascript)
Use jQuery's .on() to handle event delegation. The first element you supply is a static element (never removed / replaced). the first argument is the event you wish to delegate against, mouseover/click, etc. The 2nd argument is the element we wish to have the event fire on when the event occurs. The 3rd argument is the callback, which is the function to run when the event fires. $(document).on('event', 'elementIdentifier', function(){ //your code });

Categories : Javascript

How can you add multiple button listeners all at once?
Here's a rough logic sketch (in C#)... It basically does a single, top down pass over the layout, building an id-to-view map that can be looped through afterwards. There is know general way to do this, and so will have to be maintained along with the layout file (both need to be modified together). Say you want to do this in OnCreate of the Activity that is hosting your fragment(s) (it could possibly be done in the Fragments OnMeasure or OnLayout overrides too) Assuming your fragment's layout file has the following structure LinearLayout TextView TextView RelativeLayout EditText EditText TextView public override OnCreate() { Map<int, view> idLabels = new Map<int, view>(); View v = fragment.View; LinearLayout ll = (LinearLayout)

Categories : Java

Multiple listeners in Android
Simply try button.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View arg0) { // TODO Auto-generated method stub return false; } }) It will work perfectly untill you return true from onLongClick. If you return ture from here then setOnLongClickListener only get invoked. If you return false all Listeners belong to this button will get invoked. In your case both Listensers will get invoked whether you made setOnLongClickListener or setOnTouchListener. I hope this will help you.

Categories : Java

Multiple listeners in one class
This may be overkill for your use case, but for notifying classes about events I use an event bus (specifically https://github.com/greenrobot/EventBus). This allows you to simply post a message and every class that has registered to receive that type of message gets it. Very simple to use, and pretty small as far as libraries go.

Categories : Android

Javascript fade in multiple elements
Use your brandy dandy .fadeQueue(): working jsFiddle $.fn.fadeQueue = function(){ $(this).fadeIn(function(){ if(!$(this).is(':last-child')) // making sure we are not done $(this).next().fadeQueue(); }); } This will wait for the callback of .fadeIn() for each div before moving to the next one..

Categories : Javascript

multiple event listener in javascript
Try this: function addMultipleEvents(elements, events){ var tokens = events.split(" "); if(tokens.length == elements.length){ for(var i = 0; i< tokens.length; i++){ elements[i].addEventListener(tokens[i], (e.which == 13 || e.which == 48)?myFunc:); //not myFunc() } } } var textObj = document.getElementById("textId"); var btnObj = document.getElementById("btnId"); addMultipleEvents([textObj,btnObj], 'click keyup'); UPDATE: function addMultipleEvents(elements, events) { var tokens = events.split(" "); if (tokens.length == elements.length) { for (var i = 0; i < tokens.length; i++) { elements[i].addEventListener(tokens[i], myFunc); //not myFunc() } } } var textObj = do

Categories : Javascript

How to wait for multiple listeners with timeout
This is the code I am using, and it seems to work just fine. I won't mark it as my choice for now, because I'm not sure I'm doing it the right way... final long startTime = System.currentTimeMillis(); ArrayList<Thread> threads = new ArrayList<Thread>(); for (final ExampleTimeoutNotifierListener l : listeners) { Thread t = new Thread() { @Override public void run() { try { l.collectBeforeAction(); } catch (Exception e) {} } }; t.start(); threads.add(t); } for (Thread t : threads) { try { long timeoutLeft = timeOutInMillis - (System.currentTimeMillis() - startTime); if (timeoutLeft < 1) break; t.join(); } catch (InterruptedException e) {} }

Categories : Java

Multiple id's in single javascript click event
Use a class. $('.pro').click(function () { chart.series[0].update({ data: $(this).attr('id'); }); }); And then on each of the #pro1, #pro2, #pro3 elements add a class of 'pro'

Categories : Javascript

Javascript - efficiently insert multiple HTML elements
Not sure why you're creating a text node, but it would seem that you want to create option elements, so you could use the Option constructor instead. var msgContainer = document.createDocumentFragment(); for (var i = 0; i < response.data.length; i++) { msgContainer.appendChild(new Option(response.data[i].name, response.data[i].id)); } document.getElementById("friends").appendChild(msgContainer); Or you can use the generic document.createElement(). var msgContainer = document.createDocumentFragment(); for (var i = 0; i < response.data.length; i++) { var option = msgContainer.appendChild(document.createElement("option")); option.text = response.data[i].name; option.value = response.data[i].id; } document.getElementById("friends").appendChild(msgContainer);

Categories : Javascript

how to repeat same Javascript code over multiple html elements
Why not $('.spanlink').hide(); $('.column1of4').hover( function() { // in $(this).children('.spanlink').show(); }, function() { // out $(this).children('.spanlink').hide(); } ); It doesn't even need the ids.

Categories : Javascript

How to draw multiple canvas elements with animation using javascript?
Your ctx in _init() is always pointing to the same canvas. You need to change ctx in _init() to point to each of the 4 different canvas contexts and then draw the appropriate guage for each context.

Categories : Javascript

Multiple elements with inline "this.select" Javascript; only 1st one gets selected
After reading the Quirksmode article on the subject, I realized that the problem was exactly what was being described there - the function was being referred instead of copied. From what I gathered, it's impossible to have inline JS work like I wanted for multiple instances on a single page. My solution was to extract the JS from the HTML tags and make it into functions. I used some jQuery to do so (because jQuery!). :p Here's the HTML: <input class="span1 hasDefaultValue" type="text" name="abc" value="25" placeholder="25"> And the JS: <script type="text/javascript"> function fieldFocus() { if (this.value==this.defaultValue) { this.value=''; } else { this.select(); } } function fieldBlur() { if (!this.value) { this.v

Categories : Javascript

how to bind elements from multiple javascript files in html using knockoutjs
ko.applyBindings can only be called once per section. If you don't pass a second parameter, the section is the entire page. Do this something like that. <div id="one"> <input data-bind="value: name" /> </div> <div id="two"> <input data-bind="value: name" /> </div> <script type="text/javascript"> var viewModelA = { name: ko.observable("Anurag") }; var viewModelB = { name: ko.observable("Chaurasia") }; ko.applyBindings(viewModelA, document.getElementById("one")); ko.applyBindings(viewModelB, document.getElementById("two")); </script> That might help you.

Categories : Javascript

Adding multiple listeners which will listen to different RabbitMQ queue not working
It's a bug in the container parser, each listener gets its own container (the namespace is just a convenient way to specify common attributes). If you remove the id="myListenerContainer", it will work - because each container gets a (different) generated name. With the id specified, both beans get the same name, and the last definition replaces the first. Alternatively, declare two separate container elements, with different IDs, and each having just one listener. Thanks for finding this. Please open a JIRA issue EDIT: This issue was resolved in version 1.2.1.

Categories : Java

Adding tags and listeners to the views of a multiple times inflated XML
As far as how to tag or add onClick listeners to your views: You can add an ID to the views you want to tag and find them using findViewById. For example, LinearLayout countersList = (LinearLayout)findViewById(R.id.countersLayout); ViewGroup child = (ViewGroup) getLayoutInflater().inflate(R.layout.counter, null); child.findViewById(R.id.myButton).setTag("myTagForTheButton"); countersList.addView(child); On the second question, I'm not sure what your UI looks like, but many repeated views might call for using a ListView.

Categories : Android

How to send files and data from form with multiple divs and multiple dynamic elements as shown below?
Maybe this way will be better $(document).ready(function() { // submitting $('#upload-form').on('submit', function() { // get values var answer = $("#album_name").val(); // if empty if(answer == '') { alert('write album name'); } else { // ajax $.ajax({ url: $(this).attr('action'), // path for submit (upload.php) type: $(this).attr('method'), // here is post data: $(this).serialize(), // put all values into $_POST success: function(html) { // I get answer from upload.php alert(html); } }); } return false; // for not submitting the form }); });

Categories : PHP

Jquery multiple animations multiple elements one onclick function
you need to disable the queue for the animations that shall run at the same time: $('#effect1').click(function() { $(this).finish(); $(this).animate({ right: 200, queue : false }); $('#effect2, #effect3').animate({ left: 1000, queue : false }); }); From the jQuery API Docs: queue (default: true) Type: Boolean or String A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. [Edit] try this: $('#effect1').click(function() { $(this).finish(); var self = this; setTimeout(function(){ $(self).animate({ right: 200, queue : false }) },1); setTimeout(function(){ $('#effect2, #effect3').animate({ left: 1000, queue : false }); },1); });

Categories : Jquery

Knockout.js: Toggling Visibility Of Multiple Dom Elements Using Multiple Buttons
You could create a viewModel that contains the id of div to show. This property will be set accordingly of the button on which you click. View model: $(document).ready(function () { var ViewModel = function(){ var self = this; self.onClick =function(data, event) { var element = event.target.id.replace('button', 'text'); self.shownElement(element) }; self.shownElement =ko.observable(null); }; ko.applyBindings(new ViewModel()); }); View : <div id="text1" class="text" data-bind="visible: shownElement() == 'text1'">Text 1</div> <div id="text2" class="text" data-bind="visible: shownElement() == 'text2'">Text 2</div> <div id="text3" class="text" data-bind="visible: shownElement() == 'text3'">T

Categories : Javascript

Create Multiple Lightboxs for Multiple Elements on Single Page?
You could for example specify which lightbox id the a should have by storing it in data <a href='#' data-light='1'>Lightbox 1</a> <a href='#' data-light='2'>Lightbox 2</a> <a href='#' data-light='3'>Lightbox 3</a> The you get data in your script jQuery('a').click(function(){ jQuery('#unique-lightbox-' + $(this).data('light')).fadeIn('1000'); return false; }); Or if you have all your a in one parent. You could use their index jQuery('a').click(function(){ jQuery('.lightbox:eq('+($(this).index()+1)+')').fadeIn('1000'); return false; });

Categories : Javascript

innerHTML event with multiple Youtube players (change navbar with javascript API)
EDIT: Updated code and description below to reflect the updates to the original post Two things of possible use to you: 1) in your onYouTubePlayerAPIReady method, you'll want to use an array to hold the references to the two players (so you aren't overwriting the first one with the second). IF you don't do this, then you won't hear events from the first player object any more. This approach will also let you keep track of which players are playing, so that when a pause event comes up, the state is stored for you to find out if ALL players have stopped and you need to make your navbar change. 2) note that the event element not only has the data, but also has a 'target' attribute which will contain the ID of the player which raised the event. So you ought to be able to use that info to let

Categories : Api

How can I bind multiple elements to multiple events in jQuery?
Try this. $(document).on('click submit', '#regForm, .regDiv', function(e) { //place your code }); .on() should be like .on( events [, selector ] [, data ], handler(eventObject) )

Categories : Javascript

AngularJS Directive - How to let an event only be triggered once if otherwise it'll be triggered on multiple elements?
You need to stop the propagation of events. Events propagate upwards. In your directive put something like the following: $(elm).click(function (event) { event.stopPropagation(); }); Or, you could create a stop-propagation directive itself. This SO question has a great way of doing it.

Categories : Javascript

How to structure the code to process multiple variables from mulitple form elements in JavaScript and remember the choices?
Maybe use jquery.form.js? http://malsup.com/jquery/form/ It's a great plugin, just structure the form like it was a normal redirection form, add array in name of checkboxes <input type="checkbox" name="types[]" value="21" />Beachfront Add target URL to the form, and then... When u want to submit the form just do $('searchform').ajaxSubmit({ success: function() { // callback } ) Trigger this on checkboxes change, dropdown change etc. To make the code clean, use one selector $('#country, #s, #color input').on('change', sendAjaxForm);

Categories : Javascript

Javascript Add Event Listener for change in Audio Volume
You're looking for the "volumechange" event. var audio = document.getElementById('sample'); audio.addEventListener('volumechange', function() { console.log('changed.', arguments); }, false); I'm using the bubble phase(as opposed to capture) in this example. http://jsfiddle.net/426E6/ http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#event-definitions

Categories : Javascript

Javascript show multiple table rows from multiple select
I have fixed the problem myself, the solution was: $('table#newspaper-a tr:not(#header, #trWeekNummer)').hide(); if(List[x].selected) { $('table#newspaper-a tr:not(#header, #trWeekNummer)').each(function(){ $('td:nth-child(1)',this).each(function(){ if($(this).text() == List[x].value) $(this).parent(this).show(); }); }); }

Categories : Javascript

click event fire multiple time if i initialize marker multiple time in google maps
Every time you click the map (after the first) you move the marker: if (markerForWhatsHere != undefined) { // ... markerForWhatsHere.setPosition(whatsHereEventLatLng); But add a new 'click' event listener to it: google.maps.event.addListener(markerForWhatsHere, 'click', function (event) { alert("addressForWhatsHere "+addressForWhatsHere); if (event.alreadyCalled_) { // alert('circle clicked again'); } else { var markerTitle=markerForWhatsHere.getIcon(); if(markerTitle.indexOf("green")!=-1) { //for marker selection setMarkerTitle=markerTitle.replace("green","yellow");//changing color of marker markerForWhatsHere.setIcon(setMarkerTitle); }//end if marker is green //end of marker selection if(markerTitle.in

Categories : Google Maps

How to pass Event (e) and variables with event listeners?
Event Object has many useful properties and methods. div.addEventListener('mouseover',function(event){ bubble_info(event, info); // you can pass additional params that can be used in your handler },false); function bubble_info(event, info){ // you can access type of event from event object's properties console.log(event.type); console.log(info); // your additional parameter. }; addEventListener Documentation Use call only if you need to pass reference of this (current) object. It's syntax will be ... FunctionName.call(thisArg, arguments-list, ...); call Documentation

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.