- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
Prototype - adjacent() Method
This method finds all siblings of the current element that matches the given selector(s) and returns them as an array.
Syntax
element.adjacent([ selectors...]);
Return Value
An array of HTML elements.
Example
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function listCities() {
var arr = $('nyc').adjacent('li.us');
arr.each(function(node) {
alert(node.nodeName + ': ' + node.innerHTML);
});
}
</script>
</head>
<body>
<ul id = "cities">
<li class = "us" id = "nyc">New York</li>
<li class = "uk" id = "lon">London</li>
<li class = "us" id = "chi">Chicago</li>
<li class = "jp" id = "tok">Tokyo</li>
<li class = "us" id = "la">Los Angeles</li>
<li class = "us" id = "aus">Austin</li>
</ul>
<br />
<input type = "button" value = "List Cities" onclick = "listCities();"/>
</body>
</html>
Output
prototype_element_object.htm
Advertisements