Skip to content

Tag: javascript

Division and Power in Javascript

I have the following code to divide a variable by 100 and power it. The value in ‘b’ becomes 2 when it should be 0.01 ^ 2 = 0.0001. Why is that? Answer ^ is not the exponent operator. It’s the bitwise XOR operator. To apply a power to a number, use Math.pow(): As to why you get 2 as

Disable contextmenu for a specific container and its children

I need to disable contextmenu only inside a specific div #wrapperand its children, and not the whole page. This is what I’m doing: .. but it doesn’t seem to work. Answer You’re approaching this the wrong way: you’re adding the listener to the document, which may be ok, but it’s e…

Is it possible to attach a click event to a document fragment?

What I have tried: This example does not work. The event is not triggered. Is there any way to attach a click event to a document fragment or is it simply not possible? Answer The click event will not work in this case because document fragment is not appended to DOM structure. Here is what documentation says…

How to access first element of JSON object array?

I exptect that mandrill_events only contains one object. How do I access its event-property? Answer To answer your titular question, you use [0] to access the first element, but as it stands mandrill_events contains a string not an array, so mandrill_events[0] will just get you the first character, ‘[&#…

Lat/Long equation in Javascript

I am trying to find an equation for finding the lat/long point between two lat/long points in Javascript. It would work something like this. getMiddle(lat1, lng1, lat2, lng2) <= would return [lat3, lat3] halfway distance wise (going around the earth obviously). I found this: Link Date: 10/11/2001 at 11:41:…