<button class='block' data-id='1'>Open win 1</button>
<button class='block' data-id='2'>Open win 2</button>
<div class='win' data-id='1'>Win 1</div>
<div class='win' data-id='2'>Win 2</div>
$(document).on('click', '.block', function () {
var id = $(this).data('id'),
$target = $('.win').filter('[data-id="' + id + '"]');
$target.addClass('visible');
});
.parent {
position: relative;
width: 200px;
height: 300px;
background: #000;
margin: 0 auto;
}
.child {
position: absolute;
top: 50px; left: 50%;
width: 100vw; margin-left: -50vw;
height: 100px;
background: #f00;
}
this['foo']() // плохо
this.foo() // хорошо
// в крайнем случае никто не мешает вам сделать так:
var a = this.foo;
a();
var $menu = $('.menu'),
$items = $menu.find('li'),
num = $items.length,
current = -1;
$(document).on('keyup', function (e) {
var key = e.which;
switch (key) {
case 38:
current--;
if (current < 0) {
current = num - 1;
}
break;
case 40:
current++;
if (current > num - 1) {
current = 0;
}
break;
};
$items.eq(current).addClass('active').siblings().removeClass('active');
});
var max = 1000;
if (x < 0) {
x = max;
} else if (x > max) {
x = 0;
}