Re: [jQuery] Testing for presence of ID

2007-01-17 Thread Klaus Hartl
Dave Methvin schrieb: $(function(){ $(#second,#first)[0].focus() }); Good job, Dave! Can't think of any way to get that any shorter. $($(#second,#first)[0].focus); It is a reference, right? Oh please! Unfortunately, typeof(element.focus)!= function in IE (and I have scars to prove it)

Re: [jQuery] Testing for presence of ID

2007-01-16 Thread Gerry Danen
Absolutely correct, Sam. I was going insane, I thought... :) Gerry On 1/15/07, Sam Collett [EMAIL PROTECTED] wrote: http://blog.danen.org/ Gerry In answer to the question on your blog, I think the fields are like that because of the Google Toolbar form filling feature.

Re: [jQuery] Testing for presence of ID

2007-01-16 Thread Klaus Hartl
John Resig schrieb: I'd try something like this: $(function() { var field = $(#second_field_to_enter)[0]; if ( field ) { field.focus(); } else { $(#first_field_to_enter)[0].focus(); } }); That might get you at your desired goal.

Re: [jQuery] Testing for presence of ID

2007-01-16 Thread Jörn Zaefferer
Klaus Hartl schrieb: $(function() { var field = $(#second_field_to_enter)[0] || $(#first_field_to_enter)[0].focus(); field.focus(); }); How about.. $(function() { ( $(#second)[0] || $(#first)[0] ).focus(); }); -- Jörn Zaefferer http://bassistance.de

Re: [jQuery] Testing for presence of ID

2007-01-16 Thread Klaus Hartl
Jörn Zaefferer schrieb: Dave Methvin schrieb: $(function() { ( $(#second)[0] || $(#first)[0] ).focus(); }); Wow, the way you guys waste keystrokes it's a wonder you get anything done. :-) $(function(){ $(#second,#first)[0].focus() }); Good job, Dave! Can't think of any way to

Re: [jQuery] Testing for presence of ID

2007-01-16 Thread Dave Methvin
$(function(){ $(#second,#first)[0].focus() }); Good job, Dave! Can't think of any way to get that any shorter. $($(#second,#first)[0].focus); It is a reference, right? Oh please! Unfortunately, typeof(element.focus)!= function in IE (and I have scars to prove it) so it wouldn't be

[jQuery] Testing for presence of ID

2007-01-15 Thread Gerry Danen
In this piece of code (common to a number of pages) I want to set focus to a second input field if there is one. $(function() { $(#first_field_to_enter)[0].focus(); $(#second_field_to_enter)[0].focus(); }); If the second input field is present, focus is on the second field. If

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Erik Beeson
Try: if($(#second_field_to_enter).size() 0) { $(#second_field_to_enter)[0].focus(); } I'd be interested to hear if there's a better way. --Erik On 1/15/07, Gerry Danen [EMAIL PROTECTED] wrote: In this piece of code (common to a number of pages) I want to set focus to a second input field

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread John Resig
I'd try something like this: $(function() { var field = $(#second_field_to_enter)[0]; if ( field ) { field.focus(); } else { $(#first_field_to_enter)[0].focus(); } }); That might get you at your desired goal. --John On 1/15/07, Gerry Danen

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Gerry Danen
Thank you, Erik. Works great, and no more errors! There may be a better way (seems like there are several ways to do the same thing, from what I've seen so far), but I'll stick with this until something slick comes along. Gerry On 1/15/07, Erik Beeson [EMAIL PROTECTED] wrote: Try:

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Karl Rudd
Or try $(function() { $('#second_field_to_enter,#first_field_to_enter')[0].focus(); }); Karl Rudd On 1/16/07, Gerry Danen [EMAIL PROTECTED] wrote: In this piece of code (common to a number of pages) I want to set focus to a second input field if there is one. $(function() {

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Gerry Danen
That works too, Karl. Can you explain how it works? An interesting thing I just noticed in IE7 is that on http://test.danen.org/secure/register.htm the first, second, and fourth fields are yellow. Bizarre. If this list allows attachments, I can share a partial screenshot. Otherwise check the

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Karl Rudd
A jQuery object is an array of 1 or more objects. I'm going to simplify things down a little. $('#B, #A')[0].focus(); The selector #B, #A tries to find objects with ids of B and A (in that order). If B is not present in the document then it's just not in the list, so A is the first element

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Gerry Danen
Thank you, Karl. As I learn, I'm sure this will make perfect sense. Actually, the logic does make sense, just got to figure out where DOM fits in. Just posted a rant about IE7. I think it's broken... http://blog.danen.org/ Gerry On 1/15/07, Karl Rudd [EMAIL PROTECTED] wrote: A jQuery object

Re: [jQuery] Testing for presence of ID

2007-01-15 Thread Sam Collett
On 16/01/07, Gerry Danen [EMAIL PROTECTED] wrote: Thank you, Karl. As I learn, I'm sure this will make perfect sense. Actually, the logic does make sense, just got to figure out where DOM fits in. Just posted a rant about IE7. I think it's broken... http://blog.danen.org/ Gerry In