web design and coding services with a huge twist of creativity.

Stuff written in February, 2009

jQuery tip: Check if an element exists

Published 1 year ago, in Blog, Web

It’s a very common question for people starting out with jQuery: How do I know if element X exists? There is no standard function for you to use, however, it’s really simple to write one yourself.

What you’ll probably try to do first is to perform a check on a jQuery object, like this:

//This won't work :(
if ( $("#myId") ) {
  //awesome code here
}

The reason this method doesn’t work is that when you use the $(), you’re asking for a jQuery object. You always get a jQuery object, even if it’s an empty one. Thus, the above code always returns true, and that’s just sad.

However, the object returned by jQuery will have an internal array filled with all the elements that do match your selector. You can access this internal list’s length using the .length property. This means that, if the length of your object is greater than zero, your element does indeed exist in the DOM. Putting that into code, we get:

//This works, yay!
if ( $("#myId").length > 0 ) {
  //awesome code here
}

Although the examples shown here only checked for the existence of an element with a certain ID attribute, you can obviously use this technique with any jQuery selector you wish.

How to (correctly) size text on the Web

One of the most frequent hurdles (and one which I’ve ran into myself) Web Designers face is how to correctly size text using CSS. The most straightforward way to do this is by using absolute px values, but this comes at a price: IE6 users won’t be able to resize the text, and will be stuck with whatever you decide is best. If one of your users has some type of vision impairment, congratulations, you’ve just made someone’s life a little harder. (…) more after the jump ›

Interview with Spicy Web Designers

Published 1 year ago, in Blog, Web

Spicy Web Designers Interview

Sometime during the last week, I was sent an e-mail asking If I was interested in giving an interview. Before you start to wonder, of course I said yes. Today it was published, much to my delight, at Spicy Web Designers, a blog dedicated to interviewing and showcasing Web Designers around the world. Being my first interview ever, it was pretty fun to come up with interesting answers to the questions posed, and I hope I accomplished that. Without further ado, you can check it out here.

Web Development Project Estimator

Published 1 year ago, in Blog, Web

Web Development Project Estimator

Today I needed to provide a couple of quick and dirty budget estimates for a potential new client. If you do any kind of freelance work, you’ve probably had to do this at some point in your career. The Web Development Project Estimator, designed by the guys over at Astuteo proved to be a quick and easy solution for the task. Using this web application, you can easily lay out the tasks you’ll be performing and how long they should take you (and I emphasize should, because this number is almost always off the mark). Multiply the number of hours by your standard rate, or choose special rates for special tasks (Design Revisions I’m looking at you!), click View Estimate and you’re good to go. Simple, usable applications always get me. In a good way, I mean.

Twitter

You’ve all heard the news: Twitter is the greatest thing ever since bacon. If you hope to establish some kind of web presence for yourself, then, aside from keeping a blog, signing up with Twitter may very well be your best chance.

(…) more after the jump ›