jQuery日本語リファレンス

jQuery does not mean Japanese Query...

Attributes/API/jQuery - Sample Code

attr(key,fn)


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="/jquery/js/jquery.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("div").attr("id", function (arr) {
          return "div-id" + arr[0];
        })
        .each(function () {
          $("span", this).html("(ID = '<b>" + this.id + "</b>')");
        });

  });
  </script>
  <style>
  div { color:blue; }
  span { color:red; }
  b { font-weight:bolder; }
  </style>
</head>
<body>
  <div>Zero-th <span></span></div>

  <div>First <span></span></div>
  <div>Second <span></span></div>
</body>
</html>
      
	 
[実行結果]
[attr(key,fn) の説明へ]