I think it has already been brought up that this will not work as
expected but ... here it goes again ...
These attributes are used to set the 'default' value and are
thereafter ignored in favor of the JS object's properties. At least
that is how I understand it.
--
Brandon Aaron
On 10/2/06,
John Resig schrieb:
$.fn.checked = function(b) {
if ( b )
this.attr( checked, checked );
else
this.removeAttr( checked );
};
What do you think?
How about this:
$.fn.checked = function(b) {
if( typeof b == 'boolean') {
if(b) {
John Resig schrieb:
Hey everyone -
I stumbled across a point of optimization today, all of the following
attributes (and probably more - let me know) can only have a single
value.
checked=checked
multiple=multiple
disabled=disabled
readonly=readonly
disabled=disabled
Or even more simply:
$.fn.checked = function(b) {
return b == undefined || b ?
this.attr('checked', b) :
this.removeAttr('checked');
};
This would handle the return statements nicely, along with non-boolean
values (in case someone still wants to pass in the word checked,
for
John, these are great additions, but please be advised that in some
browsers this.attr('checked', 'checked') won't work as expected.
Do you know which browsers those are offhand? It'll help me to test
the methods, when I make them
--John
___
jQuery
John Resig schrieb:
Or even more simply:
$.fn.checked = function(b) {
return b == undefined || b ?
this.attr('checked', b) :
this.removeAttr('checked');
};
Ugh. Calling this.attr('checked', b) in the case of b == undefined just
returns the attribute, right? Creepy.
What about you doing something like this:
$.fn.checked = function(b) {
b this.attr('checked', 'checked') || this.removeAttr('checked');
}
but doing this we counting on both *attr* and *removeAttr* methods return
*true* on success (at least *attr* method).
John Resig wrote:
$.fn.checked
I strongly suggest you to compare if a variable is equal to undefined using
the typeof unary operator, because if you, someday, dicide to get these
things work on IE 5, you can not compare to the undefined constant (?),
after all, it doesn't exist on IE 5.0. Compare like this one:
if(b || typeof
leandro nascimento camarg schrieb:
I strongly suggest you to compare if a variable is equal to undefined using
the typeof unary operator, because if you, someday, dicide to get these
things work on IE 5, you can not compare to the undefined constant (?),
after all, it doesn't exist on IE 5.0.
John Resig schrieb:
John, these are great additions, but please be advised that in some
browsers this.attr('checked', 'checked') won't work as expected.
Do you know which browsers those are offhand? It'll help me to test
the methods, when I make them
I think there are overall
$.fn.checked = function(b) {
if ( b || b == undefined )
this.attr( checked, checked );
else
this.removeAttr( checked );
};
I strongly suggest you to compare if a variable is equal to
undefined using the typeof unary operator, because if you,
someday, dicide to
John, these are great additions, but please be advised that in some
browsers this.attr('checked', 'checked') won't work as expected.
Do you know which browsers those are offhand? It'll help me to test
the methods, when I make them
I think there are overall inconstencies. I put up a
Ah, this isn't a browser bug, but something of a jQuery one.
removeAttr does obj.removeAttribute(checked) under the hood, which
is not sufficient to remove these built-in properties. It would have
to do obj.checked = undefined; or some such under the hood.
--John
On 10/3/06, Klaus Hartl [EMAIL
Also notice that .innerHTML (and thus jQuery's .html() method) doesn't
always return the live checked state. In IE it tracks any dynamic changes to
the script, but in Firefox it only reflects the initial state from the
source. You can see the form text by putting this into the URL:
On Tue, 3 Oct 2006, Michael Geary wrote:
No need to go to the extra work. jquery.js begins with this:
window.undefined = window.undefined;
So undefined exists in every browser. This is a handy line of code to put
in any JavaScript - it's completely compatible with both old and new
Hey everyone -
I stumbled across a point of optimization today, all of the following
attributes (and probably more - let me know) can only have a single
value.
checked=checked
multiple=multiple
disabled=disabled
readonly=readonly
disabled=disabled
selected=selected
I'd like to add in methods
What happens if you call .checked() with no args? Wouldn't that
automatically read as false, leading to $( '#foo' ).checked() unchecking
the checkbox?
If called without any arguments, it should behave as if called with true
as an argument.
- Brian
Hey everyone -
I stumbled across a point
] On
Behalf Of John Resig
Sent: Monday, October 02, 2006 6:41 PM
To: jQuery Discussion.
Subject: [jQuery] Single Value Attributes
Hey everyone -
I stumbled across a point of optimization today, all of the following
attributes (and probably more - let me know) can only have a single
value.
checked
What happens if you call .checked() with no args? Wouldn't that
automatically read as false, leading to $( '#foo' ).checked() unchecking
the checkbox?
If called without any arguments, it should behave as if called with true
as an argument.
Sure, makes sense to me:
$.fn.checked =
I'm all for that. I've always thought it awkward of XHTML to have the
value of those attributes be the same as their name. Naturally, you may
want to support the existing syntax as well for backwards compatibility.
.attr() isn't going anywhere, nor is .removeAttr(). I assume that's
what you
20 matches
Mail list logo