var $elementToHighlight = $('#someId');
$(document).on('keydown',function(e){
if(e.keyCode==13){
//enter
$elementToHighlight.addClass('hightlighted');
}
}).on('keyup',function(){
$elementToHighlight.removeClass('hightlighted');
});
var html = '<div class="h-right">
<div class="h-lk"><a href="/registratsiya/">Регистрация</a> / <a href="/auth/">Вход</a></div>
<div class="h-basket">
<a href="#">Корзина (<span id="count_prod">3</span>)</a>
</div>';
$(html).find('#count_prod').text()
var container = document.getElementsByClassName('container')[0];
console.log(container.outerHTML);
if(empty($var)){
// code here...
}elseif(is_numeric($var)){
// another code here...
}else{
// and here
}
if(validate_text($text)){
$text_id_database = $db->select('some query here where text = '.$text);
if($text_in_database){
write_some_info();
}else{
$errors[] = 'some error';
}
}else{
$errors[] = 'Invalid text';
}
$('#anchor').click();
npm install
var empty = document.getElementsByName('not-existing-name');
console.log(empty, !!empty);
//посмотрим что там
//и что получится при приведении к булеву типу
//(как в проверке if)
//[], true
if (!ch.length) {
console.warn('Element "' +ch + '" not found');
return;
}
var arr = [{'id':1, 'amount':123, 'currency' : 'CHF'},{'id':2, 'amount':321, 'currency' : 'USD'},{'id':3, 'amount':4324, 'currency' : 'UAH'},{'id':4, 'amount':45645, 'currency' : 'USD'},{'id':5, 'amount':8972, 'currency' : 'CHF'}];
var result = {};
arr.forEach(function(item){
if(!result.hasOwnProperty(item.currency))
result[item.currency] = 0;
result[item.currency] += item.amount;
});
console.log(result)
//Object {CHF: 9095, USD: 45966, UAH: 4324}