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