Java Reference
In-Depth Information
Then you create the new <div/> element by using the Element object's constructor. You specify that
you want to create a <div/> element and you pass the attributes object. After the constructor call,
you chain a call to the update() method, giving the element some text.
var div = new Element(“div”, attributes)
.update(“Description for tab “ + num);
The fi nal step of this function is to add the element to the page. Do so with the
update()
method.
$(“descContainer”).update(div);
}
Using the update() method here means you do not have to remove the currently displaying description
in deactivateTab() because the update() method removes all preexisting content and replaces it with
the content you pass to the method.
Because you use the
update()
method in
showDescription()
, you simplify the function body of
deactivateTab()
.
function deactivateTab()
{
var currentTab = $(“tabStrip-tab-”+ currentNum);
if (currentTab)
{
currentTab.toggleClassName(“tabStrip-tab-click”);
}
}
You fi rst attempt to retrieve the currently active tab element by its id. If it can be found in the document,
then the code within the if block executes and removes the tabStrip-tab-click class from the element.
If the element cannot be found in the document, then currentTab is null and the function exits with-
out doing anything else.
Like jQuery, Prototype isn't just about DOM manipulation and language enhancement. It, too, provides
you with Ajax capabilities that are easy to learn and use.
Using Ajax Support
The Ajax support in Prototype isn't as straightforward as the high-level
$.get()
method in jQuery.
Prototype's Ajax functionality centers on its
Ajax
object, which contains a variety of methods you can use
to make Ajax calls. This object is much like the native
Math
object in that you do not create an instance of
the
Ajax
object; you simply use the methods made available by the object.
At the heart of the
Ajax
object is the
Ajax.Request()
constructor. This constructor accepts two argu-
ments: the fi rst being the URL to make the request to and the second an object containing a set of