Remove current clicked
class from element and change background
color to red
then find the next
text box. Then add clicked
class, then change background
color to white
.
Just use this piece of code within #ok
's click
event listener.
$('.clicked').removeClass('clicked').css({
background: "red"
}).next().next('[type=text]').addClass('clicked').css({
background: "white"
});
UPDATE :
You have a another weapon in your hand. That is, you are using .freqbox
class in your all input
boxes. So, You can find the last element of .freqbox
by .freqbox:last
and first element of .freqbox
using .freqbox:first
.
So, your code will be like this,
if ($('.clicked').is('.freqbox:last')) {
alert('true');
$('.clicked').removeClass('clicked').css({
background: "red"
}).siblings('.freqbox:first').addClass('clicked').css({
background: "white"
});
} else {
alert('false');
$('.clicked').removeClass('clicked').css({
background: "red"
}).next().next('[type=text]').addClass('clicked').css({
background: "white"
});
}