Question

I have strange error, and don't understand why! May be somebody can help me and tell, what wrong is here.

Page.contentSort = function () {
    var $eachblocks = (".top10_month .periods");
    var $blockhead = $(".block-head__link");
    $blockhead.on("click", function (e) {
        var $this = $(this);
        var sortvalue = $this.attr("data-date");
        e.preventDefault();
        $this.parents("ul").find("a").removeClass("active");
        this.className += " active";
        $.each($eachblocks, function () {
            if ($eachblocks.attr("data-period") === $(".block-head__link.active").attr("data-date")) {
                $(this).addclass("active");
            } else {
                $eachblocks.removeClass('active');
            }
        });
    });
};
Was it helpful?

Solution

You have missed $, So instead of

var $eachblocks = (".top10_month .periods");

Use

var $eachblocks = $(".top10_month .periods");

Additionally, You should use .data() instead of .attr()

So instead of

var sortvalue = $this.attr("data-date");

use

var sortvalue = $this.data("date");

You should go thorough jQuery Data vs Attr?

OTHER TIPS

Try to get data attribute like following, instead of using .attr();

$this.data("date");
$this.data("period");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top