AJAX
Basics
Data
DOM
Effects
Events
Forms
jQuery UI
Plug Ins
Traversing
The attr()
also gets or sets an html attribute on a DOM Element.
$(document).ready(function ()
{
$("#btnGet").click(function ()
{
var cssClass = $("#demo1").attr("class");
$("#demo1").html("The current class of this text is " + cssClass + ".");
});
$("#btnSet").click(function ()
{
$("#demo1").attr("class", "text-info")
$("#demo1").html("Setting the css class to text-info....");
});
$("#btnTest").click(function ()
{
$("#w3s").attr({
"href": "http://www.w3schools.com/jquery",
"title": "W3Schools jQuery Tutorial",
"class": "btn btn-danger"
});
});
});