I guess most of you, one time or another, has had the need to find out what style was actually rendered on an element. The easiest way to do this is through the style property followed by the specific value you’re looking for:
var intPosLeft = document.getElementById("left").style.left;
However, this only works if the CSS has been applied inline on the element. As we all (or at least most of us) have realized, having inline styles isn’t a very good and efficient approach. So then we move all our CSS to an external file and suddenly the style property return no values when checking it.
What the hell happened?
The style property is reserved for inline styles (ridiculous, if you ask me), so you need to find another way to do it. Of course, then, there’s one standard way and one Microsoft way.
I have put together a function named getStyle (yes, the name is supposed to be funny) to solve this issue for you:
I’ve updated one line for IE per zcorpan’s suggestion. The previous code worked fine as well, it’s just a matter of personal preference when it comes to code syntax.
The first parameter is an object reference to the element you want to check, the second is the CSS name of the property you want to know the rendered value for.
Interesting to know is that specific values will return a value even if it was applied by shorthand in the CSS. For example, this will work just fine:
/* Element CSS*/
div#container{
font: 2em/2.25em Verdana, Geneva, Arial, Helvetica, sans-serif;
}
var elementFontSize = getStyle(document.getElementById("container"), "font-size");
An other interesting thing is that Firefox, Opera and Safari will returned the actual pixels of a font size applied with em, while IE only return the value in em.
Web browser compatibility
This script has been tested to work in the following web browsers:
IE 5.5+
Firefox
Safari
Opera 8.5
The reason that it doesn’t work in IE 5.0 is having a function in the replace method as a second parameter. You might want to put this in a try...catch clause if you expect any users with that version, like this:
try{
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
return p1.toUpperCase();
});
strValue = oElm.currentStyle[strCssRule];
}
catch(e){
// Used to prevent an error in IE 5.0
}
Is Web 2.0 as hyped as dot-com businesses were? Are some people in every company/organization/movement more interested in fucking each others’ butts patting each others’ backs than actually doing something worthwhile? Is the web still immensely exciting? Does Microsoft have a bad reputation? Are people still blinded by different technologies as opposed to focusing on the actual goals of a product?
My whole life, as long as I can remember, I’ve been afraid of dying. The fear seems to hit me in waves, but it’s always there, constantly reminding me of my mortality.
As we grow up, most of us reach a time when we start to think about life, death, universe, why we’re here. Some think about it while lying in their beds at night staring out into the darkness, some share it with friends when drunk and some just try to suppress these thoughts as soon as they surface. What almost every person seems to have in common with each other, though, is that we desperately try to find a reason for living, a meaning with our existence.
One person might find cause through religion, while others find comfort in trying to understand as much as possible of the science we use to try to explain this phenomenon we refer to as life. But almost everyone seems to strive for an answer, a reason, a motivation to keep going.
Why am I afraid? I can’t even begin to fathom that my life will end, that my body will stop functioning and that all the thoughts, love and sorrows I bear with me will vanish. That I will cease to exist, and that I will be just gone.
I’ve heard that the older one gets, the more one comes to term with the fact that life isn’t endless. That we have been given a certain amount of time to live, and all we can do is try to make the best out of it.
You might look upon these thoughts as the ones of an unhappy man; on the contrary! My life is beyond my wildest expectations! I have a wonderful girlfriend, and a daughter that I love so much that no words of man are worthy of describing such strong feelings. I have seen so many things, been to numerous places and have met so many interesting people in my life. In my line of work I have reached a moderate success and respect, and I constantly want to become better at what I do. I also sincerely hope to constantly keep evolving into a better and less selfish human being.
But all that just makes the fear even worse to handle. To one day lose everything I’ve fought so hard for; to not be around to help and aid my family, in sorrow and in joy. At times, I can just neglect the various thoughts, and then at other times I desperately stare out into the vast emptiness hoping to find some way to be strong enough to withstand the psychological terror a fear of death brings to you.
Ever had a dream that felt more real than life itself? I’m sure you have, one time or another. Some of mine have been dreams of actually dying, waking up in the middle of the night, drenched with sweat and literary screaming my anxiety out into the room; my mind boggling and my body shaking with reluctance against the implication of death.
Maybe we do have souls, perhaps they do live on forever; maybe we’re all incarnated from who knows how long back in time. There is the slightest chance that we might remember and carry with us who we are, and that’s the fraction of hope I cling on to. Nevertheless, my fear is still there.
This article is co-written with Anne van Kesteren, W3C Member and contributor to the WHATWG and Opera specifications, R&D and QA person.
When developing a web page, DOM methods are generally the way to go when dynamically altering elements’ attributes and performing other operations. But what about adding content to a web page in the most efficient manner, both code- and performance wise? We claim that innerHTML is unmatched by any DOM methods available and that it is in most, if not all, situations the best option.
People seem to have this feeling that innerHTML is evil. Instead of one line of innerHTML you would use about twenty lines with calls to the DOM. Every such line making one change. However, innerHTML is actually not that bad. The web browser pretty much parses it much like it parses the original page and builds some DOM nodes out of it which are then inserted at the requested location. Some mutation events are dispatched for the few who care and all is fine.
When it comes to having greater scalability in a web page, especially in AJAX scenarios, innerHTML offers unmatched flexibility. There has also been benchmark tests verifying that innerHTML is more efficient compared to using DOM methods.
The fact that it is not in a standard is simply because nobody got around to it. If you read the mailing list of the W3C Web API’s Working Group you can see that Opera, Mozilla and Apple want it to be standardized and we bet Microsoft would like the same thing. New entrants in the web browser market are probably interested as well given that it has to be supported anyway. That it’s not in a standard is probably its biggest problem, apart from the name which doesn’t really scale well. On the other hand, people complain a lot about document.write() as well which is part of DOM Level 2 HTML.
So, go on! Start, or continue, to use the best tool available for the job!
As all of our lives, or rather the services we use, become more and more web-based and moving away from being locked down to one specific computer, online storage capabilities is definitely a huge part of that transformation. Sure, one can drag an USB memory stick around or a MP 3 player with a hard drive etc, but I prefer just getting online and downloading things.
As of lately, I’ve been testing the Box.net service, which has a nice sleek interface and is easy on the eyes.
The general features are:
1 GB storage for free (with prices starting at $4.99 per month for 5GB)
Private sharing
Public sharing
Desktop Sync software (upcoming)
Work groups
Uploading
There are two basic ways to upload files: through Flash and through drag and drop, and since I’m a big fan of drag and drop, that’s the option I use.
Flash upload dialog
Drag and drop upload dialog
Sharing
One great feature is sharing your files. You can either share them privately with other Box.net users or you can share them at a public URL for anyone to download, with optional password protection. Very handy, as opposed to e-mailing large files, sending them over IM or something similar.
The Public sharing dialog
What I miss
I would love to have FTP access to my account, for easy and swift uploading. Sure, Desktop Sync might happen, but I’d like to have free access to my file structure and to use my FTP tool of choice.
Conclusively, I think Box.net is going places. They’re still working on some minor issues, but they’re also very humble and open for feedback, so just let them know if you have any questions.
Except from a good service, Goowy‘s file sharing is based on the Box.net API and they have also become a module in Netvibes, so they seem get their share of attention. 🙂
The creators of Box.net also blog about the service and what’s going on in terms of competitors’ services, for anyone wanting to stay on top of things.
Most web sites out there don’t abide to web standards, use table-based layouts and are JavaScript-dependant. If you work with web development and you still haven’t got a clue, I think all hope is gone. Then you must be sincerely devoted to not doing a good job, or stray from conventions just to spite.
If you write valid and semantic markup, and add JavaScript in an unobtrusive fashion, your web site has come a long way when it comes to accessibility and SEO as well. It’s all there, one big package of building something great.
If you don’t do it that way and aren’t willing to learn, I won’t bother you anymore. It’s your problem, and something you have to deal with.
Law enforcement
Maybe I’m naive, but I don’t believe in laws enforcing accessibility. They can never be a 100% fair and balanced, and it’s a highly subjective matter. What is truly accessible? On the other hand I understand that when it comes to the public sector there has to be some regulations, when we’re dealing with matters about informing and facts that every citizen has a right to be able to get to. That I support.
For the private sector, however, I sincerely hope that reaching more visitors – thus getting more customers, getting a better search engine ranking, goodwill and actually doing the right thing should be incentive enough.
In the end, if companies choose to make their web sites inaccessible, it has to be their call. It’s their web site and they can do whatever they want with it. They will probably get bad press, like with Target, but I don’t think suing helps. Ultimately, my belief (read: vision) is that the market will cleanse itself; if you do things bad, people will choose another company to do their business with. Easy as that.
Accessibility consultants
On the other hand, we have people fighting for accessibility. Most of them good people doing it for a good cause, but sometimes their critique gets too harsh or is taken as being elitist, and that doesn’t help. Instead, companies being pointed out in such context don’t take it as constructive criticism, but instead as an attack and choose to ignore the people pointing out their flaws. It has to be done in a more respectful manner.
Also, critique is always aimed at the companies who it feels good to point the finger at. I’ve never seen anyone lash out at Flickr or Google Maps, although they don’t work properly with JavaScript disabled. The slideshow just goes dark in Flickr and Google Maps redirects you to a web page telling you that your web browser isn’t fully supported
Flickr slideshow with JavaScript disabled
The Google Maps redirect page if JavaScript is disabled
Why people leave them be? My guess is that people like Flickr so much and that Google Maps has got such a great API for building mash-ups, that they’re willing to overlook such things. Don’t. Be consistent.
A great initiative
Accessibility is often looked upon as something holding web development back, which isn’t true if it’s implemented in a correct manner. Also, some think that trying to make a web site accessible for people with any disabilities and/or platform means that it has to work exactly the same for everyone. It won’t. But make sure it degrades nice so everyone can at least partake of the information being given.
To me, just bashing inaccessible web sites doesn’t seem to do the trick. The people responsible just seclude themselves in their own shell, and hope the problem will go away. Instead, I applaud such initiatives as Accessites.org, which is about premiering good looking and functionally-wise excellent web sites that are at the same time accessible. I think that’s the way to do it, to show that something can be great and accessible.
To be hit by a meme is usually quite entertaining, and I like the nostalgic feel of the latest one. First Faruk got me and then Jonathan Snook took a stab so I have nothing else to do but abide and share some parts of my history.
One year ago
Just a little over a year ago I wasn’t entirely pleased with my employer, so out of boredom/curiosity I started this blog. It was then on Bloggerand in Swedish. When I signed up I had to choose a name for it, and in a panicky fashion I choose the corny name “Roberts prat” (which loosely translates to Robert’s talk), and it just stuck around. After a few weeks I realized that I knew a number of English-speaking people who would be interested in reading too, plus the fact that it would make it easier to reach out, so I translated the posts I had written so far into English.
My wonderful daughter Emilia was about 8 months old then.
Five years ago
I had fairly recently gotten back from my New York stint and been working for some months for a company called iBizkit. Very valuable lessons were learned and I left the company to travel around the world in 2002.
I was also (finally) living within Stockholm city, in the great Södermalm part, together with Fredrika. I was also working out a lot of the time.
Ten years ago
Ten years ago it was still seven months till I would purchase my first computer. I had moved away from home to my own apartment located in the area of Mariehäll in Bromma, 43 square meters/51.4 square yards consisting of one room and a kitchen.
I was working for UPS and had just been internally promoted to dealing with their key accounts in the terms of billing and any accounting queries they might have. I left this job at the end of 1997 to travel around in Australia for a couple of months.
Who’s next?
I had to do some serious pondering when it came to this. I wanted to choose persons that don’t normally get memes, to give them a chance. So, therefore, I proudly pass it on to Carl Camera, Stuart Colville and Shane Shepherd.
As of recently, I’ve had enough of trying to keep track of appointments and other assorted obligations. Fredrika writes things for hand in her little secret calendar, which means there’s no way I can stay on top of things going on or actually double-check when I’m not actually in the same room as here.
This led to me starting to look around for web-based calendar services, where one can enter data and it will be available from any computer at anytime, and also get reminders. Just as I was testing some services, Google were kind enough to apply to my needs and released Google Calendar.
Google Calendar has got the look and feel of GMail and other Google applications and you can just start using it with your existing Google account.
Different views
Google Calendar supports five different views:
Day
Week
Month
Next 4 Days
Agenda
Creating events
It is very easy to create an event: just click the desired date/time and enter a subject. You can then drag and drop existing events to move them to another date/time.
Notifications
It’s possible to get a notification through an alert box, e-mail or a SMS text message. I would love that last option, but it seems like it’s only available for US citizens.
Sharing
You can also share your calendar and events with others, which is a great thing! This lets you have your own calendar, share some or all events and then also color-code your and other calendars’ events to easy distinguish whose appointment it really is. Your calendar with the events labeled as public is made available at a public address, and there’s also a private address you can use in other calendar applications.
Missing features
I would love some way to synchronize the information with a PDA or cell phone and be able to use it offline.
All in all, a great service that is yet another step for me from being dependant on just one specific computer.
If you’ve ever met Chris Mills, you won’t forget him. His physical apparition is something that lingers in your mind for a while, and if you actually talk to him, it makes things even more exciting.
He’s tall, very beardy, eloquent, the Senior Editor of friends of ED, loves heavy metal, plays in two bands, has got a freakish sense of humor and is always up for adventures. What’s not to like? 🙂
And now he has started blogging with bloggEd, which, of course, is a very entertaining read. My only worry is that he’ll probably have more readers than I have within a week (if he doesn’t already), and that I’ll be superfluous very soon…
Oh well, I have to be the bigger man here and still say: go read! You won’t regret it.