Reset to default
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
data doesn’t set
data-* attributes. It manages a data cache unrelated to
data-* attributes. It initializes from
data-* attributes if there are any present, but never writes to them. To write to an attribute, use
Example: Updated Fiddle
var div = $("<div />") $(div).attr("data-foo", "bar") console.log($(div).outerHTML)
What you’re seeing is just one of the many ways this can be surprising. Another is that if your markup is
<div id="elm" data-foo="bar"></div> and at some point you use
$("#elm").data("foo") to get the value (and it will indeed be
"bar"), then you do
$("#elm").data("foo", "update"), the attribute remains
data-foo="bar" but the data managed by
data now has
foo equal to
"update". But the rule above explains it:
data never writes to
jQuery imports the
data- attributes when the element is loaded, but does not access it afterwards. The elements are stored in a jQuery internal structure. From the API:
data-attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).