Demo I have here a demo on validating if a class exist in a div. when there is no class another class is removed from a button. Basically what this does is when there are no disabled button the disable on add button will be removed. This works fine if the last thing user will do is change but if
Author: admin@master
How to make slow the Scroll-Top Speed
ScrollTop is a jquery plugin (go to top of page), trying to make slow Scroll Speed, but not working. I have changed scrollSpeed : ‘fast’, to scrollSpeed : ‘slow’, but it still fast, nothing change. JS: Call: How to make it slower or smoother, when it go to top? Answer use jquery animat…
es2015 modules – how to name exports dynamically
I would like to create a module, h, which exports one function for every HTML element. Here’s how it might be used: Here’s how that module is defined: I don’t like that every export has to be listed explictly. How do I make these dynamic? Answer how to name exports dynamically You can’…
HTML getElementsByClassName returns HTMLCollection with length of 0
I am trying to use the js document.getElementsByClassName to locate an html element, which is actually the header of a table. For the following codes: From the Firebug, I can see it log a HTMLCollection, and when I click it, it shows: So it do locate the element I want. But when I using: Then output is 0. Tha…
Longest palindrome in a string
I wrote the following function to find the longest palindrome in a string. It works fine but it won’t work for words like “noon” or “redder”. I fiddled around and changed the first line in the for loop from: to and now it works, but I’m not clear on why. My intuition is tha…
Attemping to get a div to “follow” cursor on mousemove, but with a delay
I want to create the effect similar to the old mouse trails where the div is delayed but follows the cursor. I have come reasonably close by using set interval to trigger an animation to the coordinates of the cursor. JSFiddle There are two problems that remain now: The ‘chasing’ div is very jumpy…
Crypto.js decrypt with key and iv (vector) in byte arrays
I have to decrypt some strings which are AES encrypted. Example encrypted string: 129212143036071008133136215105140171136216244116 I have a key, and a vector (iv) supplied to me in a byte-array format: Key: [ 123, 217, 20, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 115, 222, 209, 241, 24, 175, 144, 175, 53, 1…
Convenient way to wrap long SQL statements in javascript
In python, one can use “”” to wrap long MySQL statements. For example, However, if I try the same thing in javascript, there will be syntax error. Is there some kind of javascript equivalent for python’s “””string encapsulation? If no, what are some best practices for…
mongoose “Find” with multiple conditions
I am trying to get data from my mongoDB database by using mongoose filters. The scenario is that each user object in the database has certain fields like “Region” or “Sector”. Currently I am getting all the users that contain the keyword “region” in there object like so: Ho…
Ternary shorthand for foo ? foo : bar
I realized I am using the ternary operator most of the time as following: foo ? foo : bar; This becomes cumbersome, as the variable length gets quite long, e. g. appModel.settings.notifications ? appModel.settings.notifications : {}; Is there any shorthand or more elegant way of doing this? Perhaps ES6 or ES7…