I 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 the element’s name
.
For example:
$(".bold").hide(); // Selecting by class works. $("tcol1").hide(); // Selecting by 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>
jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors. All selectors in jQuery start with the dollar sign and parentheses: $().
getElementById() which is used to select the element by its id attribute. The getElementById() method returns the elements that has given ID which is passed to the function. This function is widely used in web designing to change the value of any particular element or get a particular element.
Just type the name of the element without "<" and ">" characters. For example type P, not <P> if the answer is the <P> element.
jQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element. name − The name of the property to access.
You can use the jQuery attribute selector:
$('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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With