On Jun 19, 2009, at 2:10 PM, Brandon! wrote:

So I've always had a couple questions about forms and jQuery, so I
thought I'd finally ask and see if I can get a straight answer
(they're all pretty simple).

First question: When selecting a form element by it's attribute(s),
what's the proper format?  Do I need the @ or not basically: input
[...@type="text"] or input[type="text"]  I know that both formats work,
but I don't know which is preferred.

Without the @. It was deprecated in 1.2 and removed in 1.3.

Second question: In regards to performance, is there a "best" order to
put attributes in?  inp...@name^="line_id"]...@type="checkbox"] vs input
[...@type="checkbox"]...@name^="line_id"]  Any good rule of thumb, or is
the outcome negligible?

$(':checkbox[name^=line_id]')

Not sure about performance. Probably negligible.

Third and final question: jQuery().attr('checked', true) or jQuery
().attr('checked', 'checked')?  I see it both ways, but I wasn't sure
if it makes a difference.  XHTML tells us we want checked="checked",
but I wasn't sure.

Here, .attr() is a bit of a misnomer, because it's really looking at DOM properties, not (x)HTML attributes. I'm pretty sure either one works, but I use .attr('checked', true)

Actually, when I can get away with avoiding .attr() I usually do. For example, I would do:

this.checked = true;

rather than:

$(this).attr('checked', true);


--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com

Reply via email to