I would like to go through my table's 'td's, and check for a data attribute and do something according to that attribute. I did this:
<li id="person1" data-city="Boston, New York, San Fransisco">
Person name 1
</li>
<li id="person1" data-city="down, Washington">
Person name 2
</li>
<td data-city="down"> TEST </td>
$('li[data-city*="down"]').css('color','red');
but I can't make it work for the 'td' element.
any ideas?
You can't have an orphan td
, it's not valid HTML, and jQuery will not allow you to select it. It needs to be inside a tr
, which itself needs to be inside a table
element:
<table>
<tr>
<td data-city="down"> TEST </td>
</tr>
</table>
Only then you can execute $('td[data-city*="down"]').css('color','red');
.
DEMO .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.