The jQuery Attributes function provides a quick and easy way to retrieve and manipulate attribute data in your HTML document. An example of an attribute would be the title of an anchor element, or the name value of an input element.
To do this you have must be familiar with the selector feature of jQuery. Assume you have the following HTML:
<img src="/images/testimage.jpg" id="image1" alt="testimage" />
You can get the value of the alternate text of the image by doing the following jQuery code:
$("#image1").attr("alt");
Alternatively you can change the alternate text of the image by setting its attribute using the following jQuery code:
$("#image1").attr("alt", "changedtestimage");
To best explain this we can use a text box to set its size value.
The code for this example is as follows:
<input type="text" id="sizechangebox" onkeyup="changesize()" size="15" />
<script type="text/javascript">
function changesize() {
$("#sizechangebox").attr("size", $("#sizechangebox").attr("value") );
}
</script>
You can use similar kind of code to set and retrieve nearly any HTML attribute. While it is simple to code, it can be quite powerful.





