Skip to content
Advertisement

call addEventListener in loop with variable

I am new to JavaScript. I have a 6 elements that I want to equip with very similar event listeners. I have a working brute force solution that I want to improve, but (I think) I have trouble with JavaScript closures. Working code: I a simple loop that did not work, when I found https://stackoverflow.com/a/2520602/2536029 and understand why it could

polling vs long polling

I got onto these examples showing polling vs long-polling in javascript, however I do not understand how they differ from one another. Especially regarding the long polling example, how does it keep its connection open? This is what the traditional polling scenario looks like: and this is the long polling example: Thanks! Answer The difference is this: long polling allows

Toggle visibility property of div

I have an HTML 5 video in a div. I then have a custom play button – that works fine. And I have the video’s visibility set to hidden on load and visible when the play button is clicked, how do I return it to hidden when the play button is clicked again? I’m basically just trying to toggle it

Prevent click event after drag in jQuery

I have a draggable <div> with a click event and without any event for drag, but after I drag <div> the click event is apply to <div>. How can prevent of click event after drag? http://jsfiddle.net/prince4prodigy/aG72R/ Answer I made a solution with data and setTimeout. Maybe better than helper classes. and Check the fiddle.

Moment.js and Unix Epoch Conversion

I have a web service that is returning a date as the following string: /Date(1377907200000)/ I use MomentJS to parse this to a moment object. moment(“/Date(1377907200000)/”) => Fri Aug 30 2013 20:00:00 GMT-0400 All of that is fine. But when I call unix() on the object I am given the value 1377907200. This, however, corresponds to Fri Jan 16 1970

Javascript to identify card number

I’m using a piece of JavaScript code to identify what type of credit card number a user enters. I don’t know much about JavaScript and am using code found on the web. I’ve gotten it to work with no issue, but I was hoping someone could explain to me why a specific part works the way it does. When a

Advertisement