Skip to content
Advertisement

Capture mouse position on setInterval() in Javascript

I have a function in Javascript that moves one div depending on the mouse position. This function is set on a setInterval() function and executed every second. I need to capture the mouse position like this: Ps: I cannot use the mousemove event because the function must be executed even if the mouse is stopped. Answer The only time that

What are the reasons to use the id attribute for CSS purposes? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

JSON: why are forward slashes escaped?

The reason for this “escapes” me. JSON escapes the forward slash, so a hash {a: “a/b/c”} is serialized as {“a”:”a/b/c”} instead of {“a”:”a/b/c”}. Why? Answer JSON doesn’t require you to do that, it allows you to do that. It also allows you to use “u0061” for “A”, but it’s not required, like Harold L points out: The JSON spec says

How can I invert a regular expression in JavaScript?

I have a string A and want to test if another string B is not part of it. This is a very simple regex whose result can be inverted afterwards. I could do: and invert it afterwards, like this: The problem I have is, that I need to do it within the regular expression and not with their result. Something

Reading cookie expiration date

Is it possible to read cookie expiration date using JavaScript? If yes, how? If not, is there a source I can look at? Answer It is not possible to get the expiration date of a cookie through Javascript; only key-value pairs are exposed through document.cookie.

How do I get the current date in JavaScript?

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. How do I get the current date in JavaScript? Answer Use new Date() to generate a new Date object containing the current date and time. This will give you

JavaScript mapping touch events to mouse events

I’m using the YUI slider that operates with mouse move events. I want to make it respond to touchmove events (iPhone and Android). How can I produce a mouse move event when a touchmove event occurs? I’m hoping that just by adding some script at the top that touchmove events will get mapped to the mouse move events and I

Javascript Date.UTC() function is off by a month?

I was playing around with Javascript creating a simple countdown clock when I came across this strange behavior: The days left is off by 30 days. What is wrong with this code? Edit: I changed the variable names to make it more clear. Answer The month is zero-based for JavaScript. Days and years are one-based. Go figure. UPDATE The reason

Advertisement