jquery attr

JavaScript
$('td[name ="tcol1"]')   // matches exactly 'tcol1'
$('td[name^="tcol"]' )   // matches those that begin with 'tcol'
$('td[name$="tcol"]' )   // matches those that end with 'tcol'
$('td[name*="tcol"]' )   // matches those that contain 'tcol'var some_var = $( some_jquery_selector ).attr( 'some_attribute_name' );$input.attr("attributeName", "attributeValue");$( some_item ).attr( "id", "some-id" );
// for setting multiple attributes, it's similar to the css() property. However, quotes are not always required for attr()
$( some_item ).attr({
  id: "some-id",
  // or others.
  title: "Opens in a new window",
  // attributes which contain dash(-), should be covered in quotes.
  "data-value": "internal link"
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Adding Attribute to HTML Element</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $(".add-attr").click(function(){            
            $('input[type="checkbox"]').attr("checked", "checked");
        });
    });
</script> 
</head>
<body>
    <button type="button" class="add-attr">Select Checkbox</button>
    <input type="checkbox"> 
</body>
</html>
Source

Also in JavaScript: