I want to make a userscript for a website, where I want to extract and select the date in some <td> fields.
Example:
<tbody>
<td><img></td>
<td>something</td>
<td>something</td>
...
<td style="text-align:center;">2016-02-10 13:27</td>
<td>something</td>
...
<td>something</td>
</tbody>
There are two things I want to do:
1. compare the date with another stored date (and check if it is later).
2. change the background-color of the <td> element where the date is located.
This is what I have, and it returns an empty array...
var dateArray = [];
$("td").each(function(){
if(String(this).match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)){
dateArray.push(this);
}
});
What is wrong and/or what could I do in a better way?
Thanks!
String(this)to return? You might trythis.text()instead (see API doco: .text()).String(this), so I could do the.matchto extract the dateString(object)will call the object's toString method. I don't think jQuery sets a specific method, so you'll get the built–in Object.prototype.toString , which is probably returning something like [object Object].