Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

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>

1 Answer

0 votes
by (40.7k points)

Try using the attribute selector like this:

$('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'

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...