Hi Jake,
Well, Its good to see that the discussion reared up there!! Rather
than a general discussion about use of ID / class, I think its
helpful to look at how best to achieve a result specifically with
jQuery, as core operators can sometimes make a particular task much
easier than you'd think.
As a result of your statement, Karl Swedburg posted some code which
shows jQuery at its elegant best, all using classes in a situation
where I would normally have used IDs.
To recap, my original problem was that I wanted each of four
instances of <a class="open_button"> to open a corresponding DIV <div
id="section0">, <div id="section1"> etc. and was trying to iterate
through the <a> objects applying the appropriate "click" method.
Then the "IDs are a crutch..." response came. You had suggested
linking the elements by giving them a common class:
Quote: <a class="open_btn section1"....> with the <div class="closed
section1">
However, I had not realised the potential for jQuery to dispense with
numerical identifiers altogether!
Karl's solution - which is just beautiful:
$("a.open_button").each(function(index) {
$(this).click(function() {
$('div.section:eq(' + index + ')').addClass('open').slideToggle
(1200,function() {
complete(index);
});
return false;
});
});
The power of course lies in the statement $('div.section:eq(' + index
+ ')') - now all I need to do is have <a class="open_button> and
below it <div class="section"> - no numeric identifiers, as jQuery is
doing the work iterating through the array of matching objects.
Thanks,
Steve Jones
On 20 Jan 2007, at 5:08, Ⓙⓐⓚⓔ wrote:
Gerry,
I'm an old IT guy too... I was educated in computer science, learned
lisp, taught Snobol, apl, and Algol, among others... few languages
have excited me as much as javascript+jQuery!
I tend to read this list as as testament to John's work. Some ideas
are creative, some are utilitarian and others are less exciting. When
I read about people having trouble with IDs I cringe. I know that all
those IDs are not really needed. So much is 'relative',with beautiful
jQuery commands like each and children and prev and next, it's hard to
justify the use of IDs!
Well, I just felt like venting... I guess it's the old teacher in me!
As far as samples, I've seen them all (on this list), some are
beautiful, others work well, but are less than beautiful. I tend to
read them all, and have learned from them all.
I thank John for his one year old baby (jQuery) and I know you all do!
--
Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ
On 1/19/07, Gerry Danen <[EMAIL PROTECTED]> wrote:
Hello Jake,
I'm an IT veteran (36 years) but rather new to JavaScript, AJAX
and all
that. You voice rather strong opinions on this particular subject,
and I
love to learn. Is there any chance of a tutorial or example page
on this?
Or, maybe there is an example already?
Gerry
PS: I love jQuery too...
On 1/19/07, Ⓙⓐⓚⓔ < [EMAIL PROTECTED]> wrote:
As you all know there is no replacement for ids. and 200 classes
or ids is
ridiculous! but by using a single id for the div in question and
letting the
styles cascade and letting jQuery do what, I feel, it does so
well, you can
eliminate the use of 90% of ids.
Since most good xhtml (and html) is hierarchical, css & jquery
deal well
with that hierarchy! I love seeing code like
$("#sPictures img:visible").animate({opacity: 'hide',height:
'hide',left:
window.innerWidth-90,top:window.innerHeight-90},slow,'',function()
{$(this).attr('style','display:none')})
with 1 id on a div ,instead of searching or remembering for ids
and which
was hidden!
jquery gives me that power!
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/