Skip to content

Check if a string has white space

I’m trying to check if a string has white space. I found this function but it doesn’t seem to be working: By the way, I added quotes to RegExp. Is there something wrong? Is there anything better that I can use? Hopefully JQuery. Answer You can simply use the indexOf method on the input string: Or …

How to avoid scientific notation for large numbers in JavaScript?

JavaScript converts integers with more than 21 digits to scientific notation when used in a string context. I’m printing an integer as part of a URL. How can I prevent the conversion from happening? Answer There’s Number.toFixed, but it uses scientific notation if the number is >= 1e21 and has …

How to get a DOM Element from a jQuery selector?

I’m having an impossibly hard time finding out to get the actual DOMElement from a jQuery selector. Sample Code: and in another piece of code I’m trying to determine the checked value of the checkbox. And please, I do not want to do: That gets me around the checkbox, but other times I’ve nee…

fastest MD5 Implementation in JavaScript

There are many MD5 JavaScript implementations out there. Does anybody know which one is the most advanced, most bugfixed and fastest? I need it for this tool. Answer I’ve heard Joseph’s Myers implementation is quite fast. Additionally, he has a lengthy article on Javascript optimization describing…

What is the ‘new’ keyword in JavaScript?

The new keyword in JavaScript can be quite confusing when it is first encountered, as people tend to think that JavaScript is not an object-oriented programming language. What is it? What problems does it solve? When is it appropriate and when not? Answer It does 5 things: It creates a new object. The type of…

e.which ENTER key enabled only if input field focus

I am using a e.which of jquery for running a function on press of ENTER, but I want this function to be called only if the particular input field is focused (where the cursor is blinking). My current jquery function. I want that $(“#search”).click(); to be called only if the #search_text is focuse…

Regex for replacing a single-quote with two single-quotes

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?…