Created
July 28, 2012 02:53
-
-
Save hcmn/3191518 to your computer and use it in GitHub Desktop.
JQuery: .attr() example where callback is in action.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- from JQuery API --> | |
<html> | |
<head> | |
<style> | |
div { color:blue; } | |
span { color:red; } | |
b { font-weight:bolder; } | |
</style> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
</head> | |
<body> | |
<div id="hello">Zero-th <span></span></div> | |
<div>First <span></span></div> | |
<div>Second <span></span></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$("div").attr("id", function (arr, value) { | |
return "div-id" + arr + value; | |
}) | |
.each(function () { | |
$("span", this).html("(ID = '<b>" + this.id + "</b>')"); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment