Skip to content
Advertisement

Tag: javascript

How to create an on/off switch with Javascript/CSS?

I want to have a sliding switch. On the left would be Off and on the right would be On. When the user toggles the switch, I want the ‘slider’ portion to slide to the other side and indicate it is off. I could then have a callback that takes as input the state of the toggle switch so I

How to delay the .keyup() handler until the user stops typing?

I’ve got a search field. Right now it searches for every keyup. So if someone types “Windows”, it will make a search with AJAX for every keyup: “W”, “Wi”, “Win”, “Wind”, “Windo”, “Window”, “Windows”. I want to have a delay, so it only searches when the user stops typing for 200 ms. There is no option for this in the

Get size of mouse cursor in javascript

I need to determine the width and height of the current mouse cursor used on our webpage. I need to show a div right under the cursor, and possibly to the right of it. So I need to determine the offsets of my div from the exact pointer location, so the cursor do not cover up the div. The mechanism

Strip all non-numeric characters from string in JavaScript

Consider a non-DOM scenario where you’d want to remove all non-numeric characters from a string using JavaScript/ECMAScript. Any characters that are in range 0 – 9 should be kept. How would you achieve this in plain JavaScript? Please remember this is a non-DOM scenario, so jQuery and other solutions involving browser and keypress events aren’t suitable. Answer Use the string’s

How do I get just the visible text with jQuery (or Javascript)?

I have website that converts Japanese Kanji into Romaji (roman letters): and the output shows and hides with CSS what the user needs to see depending on their input criteria. For example: <div id=”output”><span class=”roman”>watashi</span> <span class=”english”>I</span></div> The interface allows the user to flip between and output of watashi or I depending on what they want to see. The CSS

Single quotes in string with jQuery ajax

I have run into a problem where the user enters data and if there are single quotes at all, the script errors out. What’s the best way to handle single quotes that users enter so it doesn’t interfere with the jquery/javascript? UPDATE: I’m sending it through ajax to a database. here is the data parameter for a json ajax call.

Advertisement