I’m currently working on eliminating jQuery from some code that I’ve written, and I’ve got a portion of code in which I was computing both the inner and outer widths of some span elements. It seems like .getBoundingClientRect() works fine for getting the outer width of an element, but I’m a bit stuck on getting the inner width. (i.e. the
Document.write() throws Unexpected token “ILLEGAL”
Before you ask, I already searched a lot in Stack Overflow and I google it thousand times. Any other case I ever seen here helped me. Let’s go to my problem: I’m trying to use the following script in my code: But I’m using Blogger and it don’t detect correctly my code (note the red script closing tag): With this,
Loop to remove an element in array with multiple occurrences
I want to remove an element in an array with multiple occurrences with a function. This loop doesn’t remove the element when it repeats twice in sequence, only removes one of them. Why? Answer You have a built in function called filter that filters an array based on a predicate (a condition). It doesn’t alter the original array but returns
Using `this` for Parent Function inside a Nested Function
In the Apple “classs”, how can the nested function countSeeds() retrieve the value this.price? jsfiddle: http://jsfiddle.net/VGqEa/ Output Answer put var self = this at the top of Apple, and then refer to this as self instead in the nested function. i.e.: You could also put the self=this statement at the beginning of this.cutOpen, since this will still refer to the
Onclick event on list item
I’m trying to follow this answer, but rather than using a button as he does in his jsfiddle, I’m trying to use list items: http://jsfiddle.net/hqvDT/108/ It looks like it should work, but when I try to select some text and then press B (for bold), it doesn’t actually bold the text. What’s wrong? HTML: CSS: JS: Answer The problem is
Div Square, width size based on 100% height
I’m trying to make a responsive square with the width size based on the (100%) height of the element. I believe it’s impossible using only CSS. The square width should be equal to the height (100% of the large container. The large container is more than 100% of the screen). The ratio has to be width=height to keep the square.
How to create a single event handler for a variety of events in JavaScript
I want to do the following with JavaScript/jQuery: JavaScript Pseudo code! HTML Someone knows where to start? It has to be AJAX proof just like the jQuery $.on() method. I only want this for a variety of events and bind it to elements containing the action attribute. Maybe I just parse the HTML and then dynamically create event handlers but
Concrete JavaScript regular expression for accented characters (diacritics)
I’ve looked on Stack Overflow (replacing characters.. eh, how JavaScript doesn’t follow the Unicode standard concerning RegExp, etc.) and haven’t really found a concrete answer to the question “How can JavaScript match accented characters (those with diacritical marks)?” I’m forcing a field in a UI to match the format: last_name, first_name (last [comma space] first), and I want to provide
How to efficiently check if a Key Value pair exists in a Javascript “dictionary” object
Given: How to test if (1, 11) exists? Answer Most of the time very simply, with with one caveat: if the value you are looking for is undefined this will not do because it cannot distinguish between { 1: undefined } and just {}. In that case you need the more verbose test
Why scroll to top not working when I use jQuery?
I have a popup that is dynamically loading content and using overflow: auto to maintain the popup size and in turn make it scrollable. I have a link at the bottom currently using anchors to scroll to the top of the div. Unfortunately it is also forcing the page to scroll down to that point as well as scroll to