Javascript DOM How to - Set a single property to a value, on all matched elements








Question

We would like to know how to set a single property to a value, on all matched elements.

Answer


 <!--from w  w w  .  j av  a 2 s  . c o m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("button:gt(1)").attr("disabled","disabled");
        });
    </script>
  </head>
  <body>
      <button>0th Button</button>
      <button>1st Button</button>
      <button>2nd Button</button>
  </body>
</html>

The code above is rendered as follows: