$('селектор кнопки').click(function() {
$('селектор-элементов')
.not('.класс')
.slice(0, количествоЭлементовКоторымНадоДобавитьКласс)
.addClass('класс');
});
const items = [...document.querySelectorAll('селектор элементов')];
document.querySelector('селектор кнопки').addEventListener('click', () => {
items
.splice(0, количествоЭлементовКоторымНадоДобавитьКласс)
.forEach(n => n.classList.add('класс'));
});
пытался получить так:
console.log($('.wall_post_text', this)).innerText;
Но пишет undefined
.innerText
надо внутри внешних скобок было разместить, а так вы у результата вызова console.log
хотите свойство прочитать (и получаете вы никакой не undefined
, а ошибку "cannot read properties of undefined").innerText
надо получать у DOM-элемента, а не jquery объекта. Ну или замените обращение к свойству на вызов метода.$('.wall_post_text', this)[0].innerText
// или
$('.wall_post_text', this).get(0).innerText
// или
$('.wall_post_text', this).prop('innerText')
// или
$('.wall_post_text', this).eq(0).text()
// или
$('.wall_post_text:eq(0)', this).text()
// или, если элемент .wall_post_text внутри this один
$('.wall_post_text', this).text()
return json_encode($result)
наверное должно быть что-то вроде echo json_encode($result)
. Также непонятно, почему никак не обрабатывается ситуация, когда name и email отсутствуют.header('Content-Type: application/json');
. Всё-таки json возвращаете.?>
тоже не помешает - чтобы случайно не добавлять пробелы/пустые строки в ответ.dataType: "html"
было бы неплохо заменить на dataType: "json"
- по получении ответа не придётся вызывать parseJSON, response будет объектом. в чем тут логика?
(function() {
'use strict';
var func = function() { console.log(this); };
func.call(null); // выведет null
})();
var
path = 'aaa.bbb.ccc.ddd',
data = {
aaa: {
bbb: {
ccc: {
ddd: 'Hello!!'
}
}
}
};
console.log(path.split('.').reduce((p, c) => p[c], data)); // Hello!!
background: linear-gradient(to right, transparent 10%, red 30%, red 70%, transparent 90%);
The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL.UPDATE t1 SET col1 = col1 + 1, col2 = col1;
if (i > 10) {
history.shift();
}
localStorage.removeItem(history[0])
, то это не удаление нулевого элемента массива, хранящегося в localStorage, а удаление из localStorage свойства с именем, соответствующим значению нулевого элемента массива history. <div id="quote_text"></div>
<button id="get_quote">Get quote</button>
const url = 'https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&jsonp=parseQuote&lang=ru&key=';
document.querySelector('#get_quote').addEventListener('click', function() {
const script = document.createElement('script');
script.src = url + (Math.random() * 10e5 | 0);
document.body.append(script);
});
function parseQuote(data) {
document.querySelector('#quote_text').innerHTML = data.quoteText;
}