Oops! Thanks for the catch! The other thing to understand is that this wont work for browsers that have JavaScript disabled.
On Nov 11, 2009 9:16 AM, "MorningZ" <morni...@gmail.com> wrote: > Oops. got the selector wrong. It should be: > $( function() { > $(div[class^=hide-BAT].hide(); ... You still didn't get it right :-) $("div[class^=Hide-BAT]").hide(); To original poster: if you want "fast", then you can't beat CSS with jQuery's hide method have like: <div class="Hide BAT1"> <div class="Hide BAT1"> ..... <div class="Hide BAT55"> and now the CSS class "Hide" is defined like so: .Hide { display: none; } But, I'd suggest really reading into some replies above, you shouldn't be using class names this way..... if your <div> needs to be uniquely identified, then ID is the way to go, and the class name "BAT" would be used to grab all those uniquely identified <div>'s so building on that (note: id's are not supposed to start with numbers, hence the "B"): <div id="B1" class="Hide"> <div id="B2" class="Hide"> ..... <div id="B55" class="Hide"> so now on page load, it'll see: .Hide { display: none; } and not show all 55 <div>'s want to do something to item 35? function Action(id) { $("#B" + id).doSomething } Action("35") want to do something to all 55 items? $(".Hide").show() doesn't that seem easier plus more importantly make more sense? something like the suggested selector against your current structure $("div[class^=hide-BAT]").hide(); while it *would work*, you need to understand why it is slow... - first jQuery walks across the whole entire DOM tree grabbing every single <div>, and that's whether it's one you are after or not - then id needs to get every single class name, and do a (relatively to other methods anyways) slow "end with" operator Yuck.... and just think if you had 200 of those <div>'s, or 400 ! On Nov 11, 8:58 am, Joe Moore <joe.lynn.mo...@gmail.com> wrote: > Oops. got the selector wrong. I... > On Wed, Nov 11, 2009 at 8:38 AM, Joe Moore <joe.lynn.mo...@gmail.com> wrote: > > $( function() { ... > > On Nov 11, 2009 8:17 AM, "David pr" <davidpric...@gmail.com> wrote: > > > Hello, > > > Could you...