I'm attempting to grab the value of a data attribute:
<div class="relative-time" data-seconds="1449907467">12 December 2015</div>
As you see, the value is a Unix epoch time, so the value varies.
So far I've tried...
$(".relative-time[data-seconds='/[^0-9]+/']");
$( "body" ).data( "data-seconds", /[^0-9]+/ );
$('div[data-seconds="/[^0-9]+/"]');
$("body").attr("data-seconds");
$('*[data-seconds="/[^0-9]+/"]');
... But none of these return anything.
Assuming the regular expression was not correct, I swapped it out for the actual value, but there was no change.
Any ideas would be welcome.
$('.relative-time').data('seconds')- you omit thedata-prefix when using the.data()method. Note that jQuery attribute-equals selectors do not support testing against regexes. Note also that$('body').data('seconds')is not going to work, since the<body>element is not the one with the data-seconds attribute. Note further that you seem to be very confused about what the two-argument form of.data()does. I recommend reading the jQuery documentation rather than blindly guessing.