Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype Selector : simple examples

i'm just starting prototype, i was on jquery before.

I can't find easy examples on the internet about how :

  • Selecting all elements having the same id on a page (I'm doing this but it only works for the first element : $('mydiv').hide() )
  • Selecting a div that is contained in another div by their id.
  • hiding all elements that have myClass class.
like image 275
user284295 Avatar asked Feb 27 '23 03:02

user284295


1 Answers

As mentioned above you shouldn't have the same ID on a page more then once. Besides being against standards it's a recipe for potential problems since you don't know how your JavaScript will react to it. Uses classes instead.

Selecting all elements having the same id class on a page (i'm doing this but it only works for the first element : $('mydiv').hide() )

Use $$:

$$('.myclass')

Selecting a div that is contained in another div by their id.

Use $$:

$$('div#outer div#inner')

hiding all elements that have myClass class.

Use $$, each(), and hide()

$$('.myClass').each(function(d) {
  d.hide();
});

$$ is your friend.

like image 179
John Conde Avatar answered Mar 04 '23 00:03

John Conde