WNAS

happy new year

Jan 06, 2011

Just a short shout out. happy new year folks. I have been far to busy to write anything meaningful, only a handful of drafts. But still here is my promise that more posts about html5 and javascript are underway.

If only the free wasn't so absent from the freelance lately...

HTML5 safe usage 3

Oct 19, 2010 , and

As you may recal, I wrote a small piece on #html5 input types a while go here, in which I stated:

If you use an unsupported input type in a browser it falls back to text, what I didn't knew is that reading the type with JavaScript fails also. CSS attribute selectors are fine, only no JavaScript detection.

As it turns out, I was mistaken. It is quite possible to detect the type of the input elements, all it takes is the reading of the type attribute, like this:

$('input').each(function(){
var tt = this.getAttribute('type');
if(!tt)tt='text';
this.className +=' input-'+tt;
});

And voila, we have got a class on the element, with which we can style it or hook some javascript onto it...

JavaScript disabled?

Oct 13, 2010 and

nicholas zakasI just came across a small article by Nicholas C. Zakas (@slicknet), who I saw give a great presentation at last fronteers conference by the way, in which he states:

"While the percentage of visitors with JavaScript disabled seems like a low number, keep in mind that small percentages of big numbers are also big numbers."

(Via YDN Blog.)

Please remember that the same thing goes for visitors who are:

  • Using IE6
  • a screen reader.
  • a mobile phone
  • a non iphone phone, like symbian
  • ...

which one is faster?

Sep 28, 2010 and

People, is there anybody who can help me. I am wondering which one is faster...

Calling this several times in a script:

var foo = $(data).find('foo').text();
var bar = $(data).find('bar').text();

Or wrapping it in a function:

var findData = function (data, field) {
var v = $(data).find( field ).text();
return v;
};

And calling that as many times:

var foo = findData(data,'foo');
var bar = findData(data,'bar');

I know that the last solution appeals to me more, maybe 'cause it looks cleaner. But what I am wondering, which is faster?

After reading the comments, I think I'll go for:

var $data = $(data);
var foo = $data.find('foo').text();
var bar = $data.find('bar').text();

Tip of the hat to Codepo8 / Chris