Have a table column I'm trying to expand and hide:
jQuery seems to hide the td
elements when I select it by class but not by element's name.
For example, why does:
$(".bold").hide(); // selecting by class works
$("tcol1").hide(); // select by element name does not work
Note the HTML below, the second column has the same name for all rows. How could I create this collection using the name
attribute?
<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>
Here's a simple solution:
$('td[name=tcol1]')
You could get the array of elements by name the old fashioned way and pass that array to jQuery.
note: the only time you would have a reason to use the "name" attribute should be for checkbox or radio inputs.
Or you could just add another class to the elements for selection.(This is what I would do)
You can get the element in JQuery by using its ID attribute like this:
You can get the name value from an input field using name element in jQuery by:
You can use the attribute selector: