I’m running into an issue that I think is being caused by needing to double-up on some single quotes inside a string. However, JS’s string.replace uses RegEx, and I’ve never built a RegEx by hand. Can someone help me build a RegEx to find a single quote and replace it with two single quotes? Answer Try this:
Tag: javascript
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.
Knowing whether window.close() will show a security warning
In IE7, a child window opened with window.open can close itself using window.close(), but a window opened with <a href=… target=_blank> will show a security warning if the child window tries to close itself. In my application, I don’t know how my child window is opened, and I need to know (in the child window JavaScript code) whether I can
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
Round a number to nearest .25 in JavaScript
I want to convert all numbers to the nearest .25 So… Answer Here’s an implementation of what rslite said:
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