Search code examples
jquerycsscontains

How can I select the first table cell with specific content (cells in different rows)?


I have a table with several cells with the same content. I would like just to select the first one and do some CSS changes.

The cells are not in the same row (tr)

What I have so far is:

jQuery('td:contains("Februar")').css('font-weight', 'bold');

That works for all the td's with 'Februar'. I tried to select just the first one with :first, but that doesn't seem to work.


Solution

  • All of the lines below will work.

    jQuery('td:contains("Februar")')[0].style.fontWeight = 'Bold'; or jQuery('td:contains("Februar")').first().css('font-weight', 'bold'); or jQuery('td:contains("Februar")').eq(0).css('font-weight', 'Bold'); or jQuery('td:contains("Februar"):first').css('font-weight', 'bold');