function getWinCount(team) {
const el = Array
.from(document.querySelectorAll('.table-item__name'))
.find(n => n.textContent === team);
return el ? +el.closest('tr').children[3].textContent : null;
}
const wins = getWinCount('Уфа');
Мой браузер не поддерживает ES-2015
function getWinCount(team) {
var el = null;
[].concat.apply([], document.querySelectorAll('.table-item__name')).forEach(function(n) {
if (!el && n.textContent === team) {
el = n;
}
});
if (!el) {
return null;
}
do {
el = el.parentNode;
} while (el.tagName !== 'TR');
return +el.children[3].textContent;
}
$('.container').find('h2, h3').each(function(i) {
text = $('.select-list li a').eq(i).text();
не надо код, подскажите алгоритм
function shorten(val) {
if (val <= 10000) {
return val.toString();
}
const thousands = val / 1000;
const rounded = Math.round(thousands);
const deviation = Math.sign(thousands - rounded);
return `${[ '≈', '', '>' ][deviation + 1]}${rounded} т.`;
}
Цена завернута в див price prc-new
$('[name="variant"] option:checked').data('price')
$('.price.prc-new span').text()
$('input').on('input', function() {
$(this).val((i, v) => Math.max(this.min, Math.min(this.max, v)));
});
document.querySelector('input').addEventListener('input', ({ target: t }) => {
t.value = Math.max(t.min, Math.min(t.max, t.value));
});
$('.price').text((i, text) => {
const [ price, currency ] = text.split(' ');
return `${(+price).toLocaleString()} ${currency}`;
});
// или
document.querySelectorAll('.price').forEach(n => {
n.textContent = n.textContent.replace(/\d(?=(\d{3})+\D)/g, '$& ');
});
goods.each.with_index do |n, i|
puts n + " " + prices[i].to_s
end
print goods.zip(prices).map{|n| n.join(" ")}.join("\n")
function toggleClasses(block) {
const info = block.querySelector('.infoWrapper');
block.classList.toggle('marginBottom10');
block.classList.toggle('marginBottom120');
info.classList.toggle('displayNone');
info.classList.toggle('displayBlock');
}
document.addEventListener('click', function(e) {
const block = e.target.closest('.blockSvg');
if (block) {
const prevBlock = document.querySelector('.blockSvg.marginBottom120');
if (prevBlock && prevBlock !== block) {
toggleClasses(prevBlock);
}
toggleClasses(block);
}
});
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].minify.removeAttributeQuotes = false;
return args;
})
}
};
<div>{{ address }}</div>
<div ref="map"></div>
data: () => ({
coords: [ ... ],
address: '',
}),
mounted() {
ymaps.ready(() => {
const map = new ymaps.Map(this.$refs.map, { ... });
const marker = new ymaps.Placemark(this.coords, {}, {
draggable: true,
});
marker.events.add('dragend', e => {
this.coords = e.get('target').geometry.getCoordinates();
});
map.geoObjects.add(marker);
this.$watch('coords', {
immediate: true,
handler(coords) {
ymaps.geocode(coords).then(r => {
this.address = r.geoObjects.get(0).properties.get('name');
});
},
});
});
},
const className = 'dop_atr';
const maxlen = 250;
text
функцию - вызывается для каждого элемента набора, принимает текущее текстовое содержимое элемента и возвращает новое:$(`.${className}`).text((i, text) => {
return text[maxlen] ? `${text.substring(0, maxlen)}...` : text;
});
for (const n of document.getElementsByClassName(className)) {
n.innerText = n.innerText.slice(0, maxlen) + (n.innerText.charAt(maxlen) && '...');
}
// или
document.querySelectorAll(`.${className}`).forEach(function(n) {
n.textContent = n.textContent.replace(this, '$1...');
}, RegExp(`(.{${maxlen}}).+`));
document.addEventListener('click', function(e) {
const el = document.getElementById(e.target.dataset.id);
if (el) {
el.checked = !el.checked;
}
});
const buttons = document.querySelectorAll('[data-id]');
const onClick = e => checkboxes[e.target.dataset.id].checked ^= 1;
const checkboxes = Array
.from(buttons, n => n.dataset.id)
.reduce((acc, n) => (acc[n] = document.querySelector(`#${n}`), acc), {});
buttons.forEach(n => n.addEventListener('click', onClick));
$('.tab__list').on('click', '.tab__item', function() {
const
$this = $(this),
{ label, ...attrs } = text[$this.data('tab')];
$this.siblings().removeClass('tab__item--active');
$this.addClass('tab__item--active');
$('#formField').attr(attrs);
$('#formLabel').text(label);
});
onNoteAdd = {this.handleNoteAdd.bind(this)}
this.props.onNodeAdd(newNote)
const newNote = {
title: this.state.title,
text: this.state.text,
color: this.state.color
};
this.props.onNodeAdd(newNote);
this.props.onNoteAdd({ ...this.state });
.onChange = ({ target: { name, value } }) => {
this.setState({ [name]: value });
}
<input
name="title"
onChange={this.onChange}
...
/>
<textarea
name="text"
onChange={this.onChange}
...
/>
.red{border:3px solid red;;}
.green{border:3px solid red;;}
.items-list-item-colors label {
border: 3px solid red;
}
.items-list-item-colors label.active {
border-color: green;
}
class="red"
вырезаете.const containerSelector = '.items-list-item-colors';
const itemSelector = 'label';
const activeClass = 'active';
$(containerSelector).change(function() {
$(itemSelector, this)
.removeClass(activeClass)
.has(':checked')
.addClass(activeClass);
});
// или
document.querySelectorAll(containerSelector).forEach(n => {
n.addEventListener('change', onChange);
});
function onChange({ target: t }) {
this.querySelectorAll(itemSelector).forEach(n => {
n.classList.toggle(activeClass, n.contains(t));
});
}
// или
document.addEventListener('change', e => {
const item = e.target.closest(itemSelector);
if (item) {
item.closest(containerSelector).querySelectorAll(itemSelector).forEach(n => {
n.classList.toggle('active', n === item);
});
}
});