Hey all. Basically, I need “(this)” in my function to correspond to this selection:
$(".widget .portfolio img")
But I want alternative ways of running this function, one when it is cilcked, and one in intervals, like this:
function cycle()
{
var poo = $(this).attr("id");
$(".poo").html(poo);
}
$(".widget .portfolio img").click(function() {
cycle();
});
setInterval(function() {
cycle();
}, 4000);
});
The problem is that when the interval runs, the function’s value of “(this)” is that of the setInterval function – but I want it to be the selection I said above… if I could do something like this, it would be ideal:
setInterval(function() {
cycle($(".widget .portfolio img"));
...
I think I just need a simple something in the function… any ideas? Thanks in advance 🙂
pass a reference (or a jquery selector) to cycle.
or
then you can use either
cycle($(".widget .portfolio img"))orcycle(".widget .portfolio img")according to which you prefer.My preference would be passing a reference, as I could then do this: