On Text Highlight Event?

There isn’t any onhighlightext or anything like that, but a solution would be to bind onmouseup to check if any text is selected if this isn’t in a input/textarea. Edit Here’s an implementation example for you. I only tested this in Chrome/Firefox/IE7. This works in inputs as well. http://jsfiddle.net/qY7gE/ Code from JSFiddle: var t=””; function … Read more

How to Use Sockets in JavaScript\HTML? [closed]

How to Use Sockets in JavaScript/HTML? There is no facility to use general-purpose sockets in JS or HTML. It would be a security disaster, for one. There is WebSocket in HTML5. The client side is fairly trivial: socket= new WebSocket(‘ws://www.example.com:8000/somesocket’); socket.onopen= function() { socket.send(‘hello’); }; socket.onmessage= function(s) { alert(‘got reply ‘+s); }; You will need … Read more

Unobtrusive JavaScript: at the top or the bottom of the HTML code?

There are two possibilities for truly unobtrusive scripts: including an external script file via a script tag in the head section including an external script file via a script tag at the bottom of the body (before </body></html>) The second one can be faster as the original Yahoo research showed some browsers try to load … Read more

ES6 template literals vs. concatenated strings

If you are using template literals only with placeholders (e.g. `Hello ${person.name}`) like in the question’s example, then the result is the same as just concatenating strings. Subjectively it looks better and is easier to read, especially for multi-line strings or strings containing both ‘ and ” since you don’t have to escape those characters … Read more

Getting the parent div of element

You’re looking for parentNode, which Element inherits from Node: parentDiv = pDoc.parentNode; Handy References: DOM2 Core specification – well-supported by all major browsers DOM2 HTML specification – bindings between the DOM and HTML DOM3 Core specification – some updates, not all supported by all major browsers HTML5 specification – which now has the DOM/HTML bindings … Read more