I have the following to launch dialogs in my app:
$('.dialogDo').live('click', function() {
// Do we have a custom width?
var width = this.search.match(/width=(\d+)/)[1];
if (width) {
dialogDo(this.href, width);
}
else {
dialogDo(this.href, 480);
}
return false;
});
This works fine if width is defined in the href which trigger the click function above. Problem is if width is not defined it breaks. How can I deal with an undefined width while still maintaining the functionality to use a width if provided?
Thanks
One option is to have a default width in place.
Edit — match can return null if there are no matches and you can’t index into null. (thanks @Chris)