Selecting an Element by Name with jQuery
jQuery provides various methods to select elements, but the most straightforward way to select an element by its name attribute is using the attribute selector. This method allows you to specify the name attribute and value you want to match.
To select an element by name, use the syntax $('[name="element_name"]'). For instance, in the HTML provided:
<tr> <td>data1</td> <td name="tcol1" class="bold"> data2</td> </tr> <tr> <td>data1</td> <td name="tcol1" class="bold"> data2</td> </tr> <tr> <td>data1</td> <td name="tcol1" class="bold"> data2</td> </tr>
To hide the second column using jQuery, you can select it by its name attribute:
$('td[name="tcol1"]').hide();
In addition to the exact match, jQuery also offers attribute selectors that provide flexibility in matching:
The above is the detailed content of How Can I Select an HTML Element by Its Name Attribute Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!