I'm not seeing any obvious problems with the second version, except
that you should do ...
var e = $(this);
rather than just ...
e = $(this);
But probably a better way to accomplish the same thing would be to
just chain the two methods to the same selector:
$("#subsections_tabs :text")
.bind("focus", function() {
$(this).addClass("focus");
})
.bind("blur", function() {
$(this).removeClass("focus");
});
That one should work.
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Jul 18, 2008, at 6:03 AM, Stoyan wrote:
Hi all,
I had the following code fragment:
$("#subsections_tabs :text").bind("focus", function() {
$(this).addClass("focus");
});
$("#subsections_tabs :text").bind("blur", function() {
$(this).removeClass("focus");
});
I saw it's unnecessary to iterate the whole DOM twice, so i
rewrote it like this:
$("#subsections_tabs :text").each(function() {
e = $(this);
e.bind("focus", function() {
e.addClass("focus");
});
e.bind("blur", function() {
e.removeClass("focus");
});
});
However, the second code piece doesn't work as expected - there
are strange additions/removals
of classes on different elements at the same theme. I couldn't
find any dependency.
Do you find at first sight any logical difference between the two
methods which could cause troubles ?
--
Best regards,
Stoyan mailto:[EMAIL PROTECTED]