Skip to content
Advertisement

Keep the selection in a textarea

Can I prevent the loss of selection in the “onblur” event? Answer I don’t think that’s a good idea. A user with mouse in his/her hand can click anywhere on the page. If you get him/her back into the textarea, it won’t be following the principles of web accessibility.

How to declare an array in JS (like I’d do it in PHP)?

Hey, Im trying to make a nested array in JS Chrome’s debugger tells me the ), at the end of the first nested array is an “Unexpected Token” Answer From your code it looks like you’re trying to use PHP-style arrays in JavaScript. JavaScript arrays don’t work like PHP arrays. Here’s something that’s more likely to work: To explain a

Convert SVG to image (JPEG, PNG, etc.) in the browser

I want to convert SVG into bitmap images (like JPEG, PNG, etc.) through JavaScript. Answer Here is how you can do it through JavaScript: Use the canvg JavaScript library to render the SVG image using Canvas: https://github.com/gabelerner/canvg Capture a data URI encoded as a JPG (or PNG) from the Canvas, according to these instructions: Capture HTML Canvas as gif/jpg/png/pdf?

Get contentEditable caret position

I’m finding tons of good, cross-browser answers on how to set the caret position in a contentEditable element, but none on how to get the caret position in the first place. What I want to do is know the caret position within a div on keyup. So, when the user is typing text, I can, at any point, know the

Advertisement