Skip to content

Tag: html

Actual key assigned to JavaScript keyCode

I have setup an event listener: When the user presses 2 along with shift, how do I know if I should output (@) or (“)? Each users’ character mapping is different per locale. Answer Use the keypress event instead. It will reliably (barring a few edge cases) detect the character typed. There are a f…

html5, what is isContentEditable?

chrome supports the isContentEditable property (lists it in the “Inspect Element”), but reports false for INPUT, FORM – actually, everything. too me, for example, seems that INPUT, non-readonly, should be true. does anybody know what’s going on? Answer isContentEditable doesn’t h…

Detecting keydown/up events during HTML5 native drag

I’ve an element that can be dragged using native HTML5. It has dragstart, drag, and dragend event listeners assigned to it. In addition, I also have keydown and keyup event listeners assigned to document.body element. When dragging the draggable element, ondrag event will fire as expected. When I press …

Replace too long strings with “…”

Lets say we have a <div style=”width:100px;”>This text is too long to fit</div> The text in the div is dynamic. And I’d like to force the text to fit in width and not break. So i need some kind of functionality to test if the text is going to fit, and if it is not, then i’d…

javascript – shuffle HTML list element order

I have a list: Using javascript how can I reorder the list items randomly? Answer This is based on Fisher–Yates shuffle, and exploits the fact that when you append a node, it’s moved from its old place. Performance is within 10% of shuffling a detached copy even on huge lists (100 000 elements). http://…

Disable button whenever a text field is empty dynamically

Here’s my code: This works but still not efficient since the user can delete the text inside the text box and click the button while he’s holding on DELETE key. Is there a more efficient way to achieve this using javascript? Answer Add a check when the button is clicked to see if there is any text…

Open Gmail on mailto: action

How to force web-browser to navigate to Gmail and create (if logged in) new letter with filled in field ‘To’ on click on mailto:SomeMail@blabla.example? Answer There’s a Greasemonkey script. The compose URL is: https://mail.google.com/mail/?view=cm&fs=1&to=email@domain.example

javascript focus() not working on Firefox and IE?

I’m trying to appear a form and focus it, for some reason it only works on Chrome. How can I make it work across browsers? You can see it not working in here: http://jsfiddle.net/CCxrp/1/ What can I do to make it work? Thanks Answer You just need to swap the order of things: The divs have to be in the