[jQuery] Re: .hide and .show div's

2009-11-11 Thread MorningZ
 Oops. got the selector wrong. It should be:
 $( function()  {
   $(div[class^=hide-BAT].hide();
 });
 Joe

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. It should be:

 $( function()  {
    $(div[class^=hide-BAT].hide();

 });

 Joe

 On Wed, Nov 11, 2009 at 8:38 AM, Joe Moore joe.lynn.mo...@gmail.com wrote:
  $( function()  {
     $(div[class=hide-BAT$].hide();
  });

  I haven't tested this, but it should work. If not, verify the selector.

  Not sure why you are giving a unique classname to all these elements. If
  you need it, why not use the I'd attribute?

  Regards,
  Joe

  On Nov 11, 2009 8:17 AM, David pr davidpric...@gmail.com wrote:

  Hello,

  Could you help me please. I have a list of hotel which I .hide
  and .show div's to show more or less info.

  so i have

  div class=Hide-BAT1 ... 

  to

  div class=Hide-Bat55 … 

  when the user press a button I use the code
  var Hcode = $(this).attr(custom);
   $('div.Hide-' + Hcode).toggle();

  but when the page loads how do I hide this div automatically ?

  I have used

  for (i = 0; i = 70; i++)
  {
    $(div.Hide-BAT + i).hide();
  }

  But its slow and probably not the best way to do it ?

  Hope you can help and this makes sense.

  Regards

  David


[jQuery] Re: .hide and .show div's

2009-11-11 Thread David pr
Thank you all i've (you guys) crack it.


Re: [jQuery] Re: .hide and .show div's

2009-11-11 Thread Joe Moore
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...