I need to find a div with class 'controller_hover' and then be able to access it with $(this) so I can toggle the next or previous div on a controller dpad left and right.
I have this snippet for the right dpad arrow but its not working:
if (event.data.action == "right"){
$(".controller_hover").find(function(){
$(this).next('.select').toggleClass("controller_hover");
$(this).toggleClass("controller_hover");
})
}
HTML
<div class="dialog-alert dialog-visible">
<div class="dialog-border"></div>
<div class="dialog-title">Select player</div>
<div class="dialog-message"></div>
<div class="select controller_hover" data-player="1">Player 1</div>
<div class="select" data-player="2">Player 2</div>
<div class="dialog-close">×</div>
<div class="dialog-clearFloat"></div>
</div>
Got what I needed with:
if (event.data.action == "right"){
current_player = $(".controller_hover");
next_player = $(".controller_hover").next(".select");
if(next_player.hasClass('select')){
current_player.toggleClass("controller_hover");
next_player.toggleClass("controller_hover");
}
}