var keyUp = $.Event("keydown", { keyCode: 38 }),
keyDown = $.Event("keydown", { keyCode: 40 });
$(".div-up").trigger(keyUp);
$(".div-down").trigger(keyDown);
var evt = document.createEvent("Event");
evt.initEvent("keyup", true, true);
evt.keyCode = 38;
function a(e) {
alert(e.keyCode);
}
document.onkeyup = a;//функция при нажатии клавиши
document.dispatchEvent(evt);//срабатывание
<div class="cells">
<div class="js-cells-elem" data-cellscount="1">1</div>
<div class="js-cells-elem" data-cellscount="2">2</div>
<div class="js-cells-elem" data-cellscount="3">3</div>
<div class="js-cells-elem" data-cellscount="4">4</div>
<div class="js-cells-elem" data-cellscount="5">5</div>
<div class="js-cells-elem" data-cellscount="6">6</div>
</div>
<input type="text" class="js-hidden-input" style="display:none;"/>
.cells div {
margin: 1px;
border: solid 1px gray;
width: 40%;
float: left;
height: 30px;
}
var myTable = $('.cells'),
cellsElem = myTable.find('.js-cells-elem');
cellsElem.on('click', function () {
var $this = $(this),
myText = $this.text(),
myTextId = $this.data('cellscount'),
myInput = $('.js-hidden-input');
myInput.
val(myText).
show().
attr("data-id", myTextId).
focus();
});
$('.js-hidden-input').on('blur', function () {
var $this = $(this),
myInputId = $this.attr('data-id'),
myCells = $('.js-cells-elem').filter('[data-cellscount="' + myInputId + '"]');
myCells.text($this.val());
$this.hide();
});
var wrapBlocks = $('.newsBlocks'),
elemBlock = wrapBlocks.find('.newsItem'),
count = 0,
advBlock = '<div class="you-adv">Моя реклама </div>';
elemBlock.each(function () {
if (count === 3 || count === 6) {
$(this).after(advBlock);
}
++count;
});
var funcWrap = $('.js-myFunc');
var myButton = funcWrap.find('.js-next-element'),
myBlock = funcWrap.find('.js-my-block');
myButton.on('click', function () {
if (myBlock.hasClass('active')) {
myBlock.removeClass('active');
} else {
myBlock.addClass('active');
}
});
<div class="menu">
<ul>
<li><a class="js-menu-link active" href="index.php">Главная</a></li>
<li><a class="js-menu-link" href="order.php">Заказ</a></li>
<li><a class="js-menu-link" href="payment.php">Оплата</a></li>
<li><a class="js-menu-link" href="conditions.php">Условия</a></li>
<li><a class="js-menu-link" href="contacs.php">Контакты</a></li>
</ul>
</div>
$('.menu').find('.js-menu-link').on('click', function () {
if ($(this).hasClass('active')) {
return;
}
$('.menu').find('.js-menu-link active').removeClass('active');
$(this).addClass('active');
});
var menuItems = document.getElementsByClassName('js-menu-link');
var onClick = function (event) {
event.preventDefault();
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].classList.remove('active');
}
event.currentTarget.classList.add('active');
};
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].addEventListener('click', onClick, false);
}