I’ve the following sample html, there is a DIV which has 100% width. It contains some elements. While performing windows re-sizing, the inner elements may be re-positioned, and the dimension of the div may change. I’m asking if it is possible to hook the div’s dimension change event? and How to do that? I currently bind the callback function to
Tag: javascript
regex replace just the last charater of a string
This should be an easy one and I couldn’t find it anywhere. How do I replace just the last character of a string with a char from an array? Answer $ matches the end of a string, . matches any character But you should probably use string functions for this:
Redirecting child iframe to relative url, using js within iframe – but url is relative to the parent
Some interesting behavior that I didn’t expect. I have a page which contains an iframe, and in that iframe there’s a javascript function that redirects its own window. I call the iframe’s js function from the parent frame. My expected behavior is that it will redirect the iframe to a new page, relative to the iframe’s existing location. Instead, it
Why does this regex replace remove a symbol at the start, but not at the end?
I am trying to remove the apostrophes from this string: “‘234324234234234236548723adf83287942′”. I am trying to use this: to try and get “234324234234234236548723adf83287942”. But I can’t seem to crack it. How do I remove the apostrophes (‘)? Answer Just use ‘ on it’s own with the global modifier: Alternatively, if the quotes are always at the start and end, you don’t
Getting timestamp from mongodb id
How do I get the timestamp from the MongoDB id? Answer The timestamp is contained in the first 4 bytes of a mongoDB id (see: http://www.mongodb.org/display/DOCS/Object+IDs). So your timestamp is: and
How to capture the text of an Select option?
So I have this: How would I go about grabbing the ‘text’ of the options here? The problem is, it needs to be ‘dynamic’, in the sense I need the text for the currently selected option… I know a manual, static way of getting the text… That will grab “This is You”… But how do I get it for the
Track mouse speed with JS
What’s the best way to track the mouse speed with plain JS/JQuery? I’d like to track how fast a user moves the mouse in all directions (up/down/left/right). Answer Sparklines has a nifty example of tracking mouse movement and graphing it. Their code is available in the source of their site starting at line 315. Simple and effective. Here is the
document.getElementByID is not a function
I’m learning jQuery and was following a tutorial, a very strange error has perplexed me. Here’s my html : and The jQuery : When I add elements By hitting the return key, there’s no problem. But When I click the Submit Button then firebug shows this error I tried to use jQuery instead replacing it with This time the error
Unlimited arguments in a JavaScript function
Can a JavaScript function take unlimited arguments? Something like this: I am trying: But this doesn’t work (output is only the first argument). Or the only way is: Thanks Answer There’s a weird “magic” variable you can reference called “arguments”: It’s like an array, but it’s not an array. In fact it’s so weird that you really shouldn’t use it
Backbone View events not firing
I am using Rails3 as my backend and Jammit to asset… Now I am trying to not compress and even package the assets. The simple event don’t get run, but the alert(‘asd’) int initialize is working as expected. I have already tried other kinds of events in other objects too, but it didn’t work. My code as follow: and my