Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype: find all elements with a certain class?

Tags:

prototypejs

Using the Prototype js framework, how do you find all elements with a certain class?

like image 308
readonly Avatar asked May 22 '09 18:05

readonly


People also ask

How do you select all elements with the same class?

To select elements by a given class name, you use the getElementsByClassName() method: let elements = document. getElementsByClassName('className');

What does get elements by class name return?

The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class name(s). When called on the document object, the complete document is searched, including the root node.

How do you select an element with the class name example?

To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)

How do you select all p elements inside a div element?

Use the element element selector to select all elements inside another element.


2 Answers

You can use the $$ function to get elements by class:

$$(".myclass")

Will give you an array of elements you can iterate over. This function allows you to use any css selector to get the elements, too:

$$("li.myclass")
$$("p#test")
like image 157
Codebeef Avatar answered Oct 17 '22 23:10

Codebeef


http://prototypejs.org/doc/latest/dom/dollar-dollar

$$ lets you pass in any css selector.

$$('.class')
like image 33
Dmitri Farkov Avatar answered Oct 18 '22 00:10

Dmitri Farkov