jquery - Iterate two loops, hover one button, change corresponding element -


i have 2 loops, 1 set of buttons , other set of spans. when hover on 1 of buttons, want corresponding span change colour. both have count on them going 0 upwards, should tie 2 items together.

this attempt, going wrong? doesn't seem anything.

$('.toggle').each(function () {             var item = $(this).data();             $('.feature-dot[data-number="'+ item +'"]').css('background-colour', 'green');         }, function () {             $('.feature-dot[data-number="'+ item +'"]').css('background-colour', 'yellow');         }); 

button loop:

        <li>             <a class="toggle dot-link-<?php echo $count; ?>" data-number="<?php echo $count; ?>" href="javascript:void(0);"><?php the_sub_field('title'); ?> <span class="opener">+</span><span class="closer">-</span></a>             <span class="inner">                 <?php the_sub_field('content'); ?>             </span>         </li> 

dot loop (corresponding items):

<span class="feature-dot dot-<?php echo $counter; ?>" data-number="<?php echo $counter; ?>" style="top:<?php echo $top; ?>px;left:<?php echo $left; ?>px;"></span> 

you not passing key .data() method, use like

var item = $(this).data('number'); 

and had use .hover() function instead of .each() attach event handler.

$('.toggle').hover(function () {     var item = $(this).data('number');     $('.feature-dot[data-number="' + item + '"]').css('background-color', 'green'); }, function () {     var item = $(this).data('number');     $('.feature-dot[data-number="' + item + '"]').css('background-color', 'yellow'); }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -