Posts in the "JavaScript" Category

How to avoid automatic type conversion in JavaScript

Published on Friday, May 16th, 2008

A very common problem when people code JavaScript, is that they don’t take automatic type conversion into account. As a result, there are numerous weird errors and JavaScript is getting a lot of blame for being loosely typed. Therefore, I’d like to show you an easy way to avoid that problem.

Continue reading

DZone article about AJAX and element selection with DOMAssistant

Published on Thursday, May 15th, 2008

DZone asked me to write an article about DOMAssistant, so I chose to give an introduction to how to work with element selection and especially different ways of making AJAX calls. Please read Making Element Selection and AJAX simple with DOMAssistant for more information.

How to hide and show initial content, depending on whether JavaScript support is available

Published on Tuesday, May 13th, 2008

Many people ask me how I choose to address an situation where all content in a web should be available without JavaScript, but certain parts hidden if JavaScript is enabled.

Continue reading

PictureSlides plugin released for DOMAssistant

Published on Tuesday, May 6th, 2008

We have just released a PictureSlides plugin for DOMAssistant, with which you can create picture slideshows, image presentations and also complete picture galleries.

Continue reading

Event delegation with JavaScript

Published on Sunday, May 4th, 2008

There has been a fair share about JavaScript and event delegation, but since a lot of people doesn’t seem to have read it, I thought I’d re-iterate the point here. The more the merrier, right? :-)

Continue reading

Interviewed for DZone/Web Builder Zone

Published on Friday, April 25th, 2008

I have been interviewed for DZone/Web Builder Zone, where I mainly talk about DOMAssistant. Hopefully you get answers to some questions you have possibly had. :-)

Where to include JavaScript files in a document

Published on Wednesday, April 23rd, 2008

Today I thought we’d talk about how, or rather were in the document, to include JavaScript files.

Continue reading

Do you validate your JavaScript code?

Published on Thursday, April 17th, 2008

Writing about whether people validate their CSS, it made me wonder about how/if people ensure the quality of their JavaScript code.

Continue reading

Memory - an Adobe AIR application

Published on Monday, April 14th, 2008

For some time, I’ve wanted to play around with Adobe AIR and see what it’s like. I’m also a sucker for very simple, yet addictive, games, so now was the time!

Continue reading

JavaScript loop performance

Published on Friday, April 11th, 2008

When developing JavaScript, performance is one of the vital things. Therefore, I thought I’d share the performance of loops with JavaScript, and give some advice.

Continue reading

DOMAssistant 2.7 released - better, faster, slimmer + new features!

Published on Wednesday, April 9th, 2008

The new version of DOMAssistant, 2.7, is finally out and my impression is that it is a very stable and solid release. Faster CSS selector performance, new features while at the same time a smaller file size.

Continue reading

Web Developer recommendations: Lim Cheng Hong and Pelle Wessman

Published on Tuesday, March 25th, 2008

Today I though it would be a good time to tell you about two web developers who I would really like to recommend to you: Lim Cheng Hong and Pelle Wessman In Swedish (Pelle’s blog).

Continue reading

DOMAssistant news - New plugins, TextMate bundle and ten times faster than the competitors in IE 8

Published on Monday, March 10th, 2008

A number of exciting things have been going on in the DOMAssistant camp, so I thought I’d fill you in with some of the latest. We’re talking plugins, developer tools and taking a glimpse into the future.

Continue reading

IE 8 beta 1 available for download - some quick takes

Published on Friday, March 7th, 2008

For those of you who have missed it, IE 8 beta is now available for download. Let’s take a quick look on what’s in it.

Continue reading

The form that left

Published on Friday, February 29th, 2008

The other day, I encountered a form submission behavior I didn’t expect, nor don’t have any solution for.

Continue reading

DOMAssistant lives - version 2.6 released with overall fastest CSS selector performance and plugins

Published on Wednesday, February 20th, 2008

Almost a month ago, I wrote a hesitant post about DOMAssistant in DOMAssistant - Why bother?, so it’s about time to talk about that again.

Continue reading

DOMAssistant - Why bother?

Published on Friday, January 25th, 2008

Maybe I’m just writing this because I’ve been feeling a bit low lately, but I do wonder if there’s any idea that I put any more time into DOMAssistant.

Continue reading

DOMAssistant goes MIT License

Published on Monday, January 14th, 2008

I’ve had some people worrying about the GPL license I’ve used for DOMAssistant, and it being too strict so they can’t use it in their commercial project.

Therefore, DOMAssistant has now changed to a MIT License, which basically means you can pretty much do anything with it! :-)

Enjoy!

DOMAssistant 2.5.6 released - AJAX module post method has been fixed (now 2.5.7 version)

Published on Saturday, January 12th, 2008

I just released DOMAssistant 2.5.5 yesterday, but with the feedback given, some tweaks had to be made to the new AJAX module post method. Instead of updating the same version multiple times, which is wrong, I’ve new made a new minor release where the issues have been taken care of.

So, download the new 2.5.6 version if you’re using DOMAssistant.

Updated January 14th

Just as mentioned by chenghong, I made a mistake and stripped the URL in AJAX GET requests as well. Something I knew, but that’s what I get for preaching about assertions but not applying it properly to my own code. I guess my intuition took overhand for a while. ;-)

Anyway, I’ve released a 2.5.7 version of DOMAssistant now (available for download) where everything should be sorted. If you’re using the 2.5.5 or 2.5.6 version, everything should be working fine but the AJAX module’s get and post methods, but please update to make sure you have the latest working version.

I sincerely apologize for any inconvenience this might cause you.

DOMAssistant 2.5.5 released, with improved event handling, replaceClass and end methods

Published on Thursday, January 10th, 2008

I have just released DOMAssistant 2.5.5, which contains some very useful features and improvements, and a CSS selector bug fix.

Continue reading

What’s your level of code assertions?

Published on Monday, January 7th, 2008

Last year in November, Andy Hunt, of The Pragmatic Programmer and Agile Manifesto, was invited to speak exclusively to our company, and some things he said made me start thinking.

Continue reading

AdvancEd DOM Scripting - a book review

Published on Wednesday, December 19th, 2007

Quite recently I finished reading the book AdvancEd DOM Scripting by Jeffrey Sambells, together with Aaron Gustafson.

Continue reading

DOMAssistant 2.5 released - CSS selector support, new AJAX methods and more goodies added!

Published on Monday, December 17th, 2007

After listening to a number of JavaScript developers, seeing how they work in real life and analyzing their needs, I’m happy to provide the heavily updated DOMAssistant 2.5!

Continue reading

Ving.se being Sweden’s best web site? I think not

Published on Wednesday, December 5th, 2007

What’s in an award, really? Swedish computer magazine Internetworld has just given the Sweden’s Best Web Site 2007 award to the supposedly best web site in Sweden.

Continue reading

@media Ajax - the presentations

Published on Saturday, November 24th, 2007

As promised in my @media AJAX - Journeys and stories post (now updated with pictures!), this one will focus on the presentations during the conference.

Continue reading

@media Ajax - Journeys and stories

Published on Thursday, November 22nd, 2007

I’m just back from @media AJAX, which was a great experience! I thought I’d split up my stories in two posts: this one about the journey and social aspects, and the next one about the presentations. This post will be long enough anyway, so get a drink, lean back, and enjoy the ride. :-)

Continue reading

Ticnet.se - an example of when online ticket booking goes wrong

Published on Tuesday, November 13th, 2007

I’ve always wondered when non-functioning web sites will start to be replaced by good ol’ real-life stores, which people will go to instead of using the online service. Yesterday it happened with Ticnet.se

Continue reading

Stop using poor performance CSS expressions - Use JavaScript instead

Published on Tuesday, November 13th, 2007

Since the CSS support in Internet Explorer, especially in versions prior to Internet Explorer 7, has been lagging quite substantially, clever web developers have started using CSS expressions to mimic CSS functionality. However, few realize how this affects performance.

Continue reading

Going to @media Ajax in London 19-20 November

Published on Thursday, November 8th, 2007

November 18th-20th, I will be in London to attend the @media AJAX conference.

Continue reading

YSlow - a nice performance plugin to Firebug

Published on Wednesday, October 31st, 2007

I’m sure you follow web standards, write semantic HTML and separate content (HTML) from presentation (CSS) and interaction (JavaScript). It’s all accessible and lean at the same time. So, what’s the next step. Performance, I tell you!

Continue reading

Releasing DOMAssistant 2.0 - Chainability, AJAX module, DOMReady, XPath and more

Published on Thursday, September 20th, 2007

Updated October 4th 2007

The DOMAssistantCompressed JavaScript file has been updated. My compression approach was a little too effective for the special DOMReady fix for Internet Explorer, so necessary code for optimal performance was unfortunately removed. This has now been addressed, so please download the new version if you use the compressed file.

Updated October 19th 2007

The DOMAssistantCompressed JavaScript file is updated again. I noticed a problem with the elmsByAttribute method in IE where the compression resulted in a wrong reference, returning incorrect results. Download the new version and it will be fine.

Tired but proud, I would like to announce the 2.0 release of DOMAssistant! Refactored code and new features will improve what is already a vital and must-have JavaScript library for me.

Continue reading

DOMAssistant gains popularity

Published on Thursday, September 6th, 2007

So, this post is just about selling DOMAssistant to you. However, it is also a way for me to express gratitude for the mentioning and usage of it in two recent cases.

Continue reading

DOMAssistant fix for addEvent method peculiarity in IE

Published on Friday, May 11th, 2007

I don’t know why, but problems seem to always be especially good at showing their ugly face at work in Friday afternoons/evenings. This time around, IE (big f**king surprise) displayed an odd behavior when using the addEvent method on the window object.

Continue reading

getElementsByClassName updated and revised

Published on Friday, May 11th, 2007

Just a small note to those of you who use my getElementsByClassName script: it has been updated for performance reasons and flexibility reasons.

Continue reading

FlashReplace - A light-weight JavaScript to insert Flash movies into your web page

Published on Thursday, April 19th, 2007

Updated April 20th

I’m so used to having a $ method for accessing elements. Nevertheless, the idea is of course that FlashReplace should be stand-alone, so I replaced it with the standard document.getElementById.

Updated April 20th

Although I didn’t encounter any problems with not using an embed element (to have valid HTML code output), it has been strongly recommend that I use it to ensure maximum compatibility. Therefore, it has been added and the file size is now 2.1 KB.

Updated June 3rd

I’ve gotten a few e-mails asking how to add variables to the Flash movie, so here are some options:

The simplest way is to just do it through a querystring. I.e. “movieFileName.swf?testVar=hello”.

Another option is to reference the movie and do it something like this:

document.getElementById("movieName").SetVariable("testVar", "hello");

Ok, everyone and his mother are creating scripts to include Flash into a web page. I wanted to have my own version, but with less and more readable code, so here’s my JavaScript to include flash : FlashReplace.

Continue reading

Free Movies Free Movies

AJAX Suggestions - a new JavaScript library for you

Published on Monday, April 9th, 2007

Updated April 10th with a couple of features per comment suggestions

Ok, I’ve added a couple of features and settings based on the comments I’ve got. The additional settings are:

hideResultsOnDocumentClick
If a click on the document should hide the results list.
itemInsertValueSetFocusToInput
If the focus should be set to the input element, once an item has updated the input element’s value (by initially having the itemInsertValueIntoInputClassName CSS class).
hideResultsWhenInsertValueIsSelected
If the results list should be hidden when the input element’s value is updated.

Another additional feature is that if you use the arrow keys to navigate the results list, arrow up from the first item as well as arrow down from the last, will set the focus back to the input element.

Updated April 11th

Changed the license to a Creative Commons Deed.

Updated April 13th

I got an e-mail with the suggestion to turn off the web browser autocompletion feature of the inout element. I think it was a good idea, so I have now added it as a setting:

turnAutoCompleteOff : true

When most people need some kind of intellectual challenge, they do crosswords, sudokus, IQ tests, read up on philosophy or something similar. Me? I write some JavaScript. :-)

Continue reading

Weird XMLHttpRequest error in IE - just one call allowed

Published on Wednesday, April 4th, 2007

Recently in a project I’ve been working on, I stumbled across something that I haven’t seen before: one AJAX call was possible to make in the web page, but after that it stopped working.

Continue reading

Stop resizing my web browser window!

Published on Friday, March 30th, 2007

One of my top annoyances when surfing around is when some “clever” web developer has chosen to use a script that resizes the web browser window to what they think suits their web site. Stop doing that! The size of my web browser window is the one I like, and I very much like to keep it that way.

Do you hate when this happens to? Please sign the petition (or, rather, write a comment) below, to state:

No, we don’t accept you resizing our web browser window anymore! You resize, and we’ll leave your web site forever.

Indentation of code

Published on Monday, March 26th, 2007

One thing that I’ve always taken for granted how to do is the indentation of code. Sure, people place characters like { either on the same line as the CSS rule/JavaScript function name, or on the following, and that’s just fine. But what I mean here is how to accomplish the actual indentation.

Continue reading

Is invalid code created through JavaScript ok?

Published on Monday, March 12th, 2007

When developing web sites with heavy interactivity, your scripting skills are really put to the test. And, sooner or later, you will be put in a situation where it’s a fine line between following web standards and what’s best from a performance and structure perspective. One question that follows that is: is it ok to apply invalid attributes via script to elements?

Continue reading

DOMAss renamed to DOMAssistant, with added Prototype/jQuery compatibility

Published on Friday, March 2nd, 2007

After I released DOMAss, I’ve gotten a number of e-mails from people telling me how happy they are with it and how well it compares to other libraries. They only have one problem: the name. What they’re saying is that they can’t use such a name, albeit funny, in production for large web sites and in their customers’ code.

Happy to oblige, the library is now renamed, with added side-by-side compatibility for other JavaScript libraries such as Prototype and jQuery.

Continue reading

Pro JavaScript Techniques by John Resig

Published on Tuesday, January 30th, 2007

For a time now, I’ve wanted to read an advanced book about JavaScript, to perhaps fill in the blanks, and to get some inspiration and different perspective on how to implement various features.

Therefore, after some consideration, I picked up Pro JavaScript Techniques by John Resig.

Continue reading

DOMAss - The DOM assistant

Published on Thursday, January 25th, 2007

Updated March 2nd 2007

DOMAss now has a new name, DOMAssistant, and it is also possible to run it side-by-side with other JavaScript libraries such as Prototype and jQuery. For more information, please read: DOMAss renamed to DOMAssistant, with added Prototype/jQuery compatibility.

Updated March 6th 2007

Per Zimmerman made me aware of the fact that I wasn’t as consistent when checking for names and whitespace in the addClass and removeClass as I am in the hasClass method, so this has been fixed to address any potential issues you might have had. Just download the DOMAssistantCSS JavaScript file and you should be good to go. :-)

Updated April 11th 2007

Changed the license to a Creative Commons Deed.

Updated May 11th 2007

Minor fix for strange behavior in IE when using the addEvent method on the window object. For more information, please see DOMAssistant fix for addEvent method peculiarity in IE.

Updated July 11th 2007

PDF documentation added, kindly created by Michael Frühmann.

Updated September 20th 2007

DOMAssistant 2.0 released!

Updated October 4th 2007

The DOMAssistantCompressed JavaScript file has been updated. My compression approach was a little too effective for the special DOMReady fix for Internet Explorer, so necessary code for optimal performance was unfortunately removed. This has now been addressed, so please download the new version if you use the compressed file.

Updated October 19th 2007

The DOMAssistantCompressed JavaScript file is updated again. I noticed a problem with the elmsByAttribute method in IE where the compression resulted in a wrong reference, returning incorrect results. Download the new version and it will be fine.

When I released my EJ code, while I felt that it contained very useful functions, it didn’t feel properly packaged. Also, I’ve always wanted a proper base to stand on for various DOM interaction, so I didn’t have to start from scratch in every project.

So now, I proudly present DOMAss!

Continue reading

With these web sites, would you say the web standards war is won?

Published on Wednesday, January 24th, 2007

Some people like to proclaim that the so-called web standards war, i.e. a wide-spread usage of web standards, is over. Let me take a couple of web sites as example why I don’t agree:

Continue reading

Worst code you’ve ever seen?

Published on Tuesday, January 16th, 2007

Once every now and then you come across code that is so ghastly, so terrible, that it almost makes you go blind! While fighting the pain, you (think) you can be almost sure of one thing: this must have been done on purpose!

Continue reading

Initial focus to a text field - good or bad?

Published on Monday, November 13th, 2006

I think that in (almost) every project I work in, when a web page contains one or more form elements, the most common question is: should we set initial focus to the first element in the form when the page has loaded? Heated debates follow, where people argue very convincingly for their view on it.

However, to me it isn’t an easy black or white-question.

Continue reading

JavaScript frameworks - concept vs. code libraries

Published on Thursday, November 9th, 2006

Personally, I’ve never been a fan of huge JavaScript libraries, an opinion that was probably clear from what I wrote in my EJ - The only JavaScript library you’ll ever need post. Even if they’re written by very competent web developers, they almost always consist of more functions and methods that are necessary.

However, I’d like to take this opportunity to explain the important difference between the two major types of JavaScript libraries: concept and code libraries.

Continue reading

EJ - The only JavaScript library you’ll ever need

Published on Tuesday, November 7th, 2006

Updated March 2nd 2007

If you like this code, I sincerely recommend that you take a look at the DOMAssistant JavaScript library.

The web is littered with full-blown JavaScript libraries who say they will save your day and make your web development life much easier. You get encouraged to include these “mere 80 KB” libraries that is supposed to be the solution to all your needs, and practically make the web site work by itself. Needless to say, I’m not a big follower of JavaScript libraries,, especially since they almost always include lots of superfluous code, so I thought I’d put together a tiny library with only essential JavaScript functions.

The result of that is EJ - Essential JavaScript.

Continue reading

Want to take your JavaScript knowledge to the next level?

Published on Wednesday, October 25th, 2006

Have you dabbled with JavaScript for a long time but feel that you don’t really know how to get to the next level? Or are you one of the recent converts that till only recently only knew HTML and CSS, but has come to the realization just how cool and funky things you can achieve with JavaScript?

If you want to get really good at JavaScript and definitely move on to the next level, I have something for you to read.

Continue reading

Minor bug fix for GLT

Published on Thursday, October 19th, 2006

With GLT, a side-effect happened in Firefox when using GLT for any link; the status text simply wasn’t shown in the web browser status field. This issue has now been addressed. Just download the new JavaScript file and things should work fine.

Please let me know if you encounter any problems.

Top results