How to add setInterval?

Good afternoon.

Wrote a script:
$(document).ready(function() {

 $(".slider .images img, .slider .data .position a.href_title").hide();
 $("ol.switch li:first").attr('id', 'current').show();
 $(".slider .images img:first, .slider .data .position a.href_title:first").show();

 $("ol.switch li").click(function() {

 $("ol.switch li").removeAttr("id");
 $(this).attr('id', 'current');
 $(".slider .images img, .slider .data .position a.href_title").hide();

 var activeTab = $(this).attr("class");
$('.'+activeTab).show();
 return false;
});

});


Trying to add setIterval:
$("ul.tabs li").interval = setInterval(function(){
 $("ul.tabs li").removeClass("active");
$(this).addClass("active");
 $(".tab_content, .tab_test").hide();

 var activeTab = $(this).find("a").attr("class");
$('.'+activeTab).show();
 return false;
}, 1000);


But the problem is that I need to pass in this information about the current tab.
Tell me how to solve this problem?
Thanks in advance.
July 9th 19 at 10:55
1 answer
July 9th 19 at 10:57
Solution
var handler = function(){
 $("ul.tabs li").removeClass("active");
$(this).addClass("active");
 $(".tab_content, .tab_test").hide();

 var activeTab = $(this).find("a").attr("class");
$('.'+activeTab).show();
}

$("ul.tabs li").interval = setInterval(handler.bind(this), 1000);
Well, you do not mindlessly copy code and understand what its meaning. You need to pass to bind() the correct context - now there is a window. - aniya commented on July 9th 19 at 11:00

Find more questions by tags HTMLJavaScriptjQuery