option:selected
, суммируя data-price
и закидывая data-name
в массив:$('.select-spa').on('change', function() {
const data = $('option:selected').get().reduce((acc, n) => {
acc.names.push(n.dataset.name);
acc.price += +n.dataset.price;
return acc;
}, { names: [], price: 0 });
$('.chose').text(data.names.join(', '));
$('.to-pay .result-select').val(data.price);
});
$('.price-inp').change(function() {
const val = Math.round($(this).val() / 100) * 100;
$(this).add('.result').val(val);
});
$(document).ready ( function(){
$('.faces_choice_area').find('span').live('click',function(){
$(this).addClass('ch').siblings().removeClass('ch').parents('div.faces').find('span.faces_choice').eq($(this).index()).addClass('ch').siblings('span.faces_choice').removeClass('ch');
});
});
Подсказали что правильно сделать через атрибут data-*
data-key
, как у тех элементов, по клику на которые блоки надо показывать. По клику хватаете все блоки и показываете те, у которых data-key
совпал с кликнутым, остальные скрываете:const key = 'key';
const buttonSelector = `a[data-${key}]`;
const contentSelector = `div[data-${key}]`;
$(document).on('click', buttonSelector, function() {
$(contentSelector)
.hide()
.filter((i, n) => n.dataset[key] === this.dataset[key])
.show();
});
// или
document.addEventListener('click', ({ target: t }) => {
if (t = t.closest(buttonSelector)) {
document.querySelectorAll(contentSelector).forEach(n => {
n.hidden = n.dataset[key] !== t.dataset[key];
// или (надо будет в стили добавить .hidden { display: none; })
n.classList.toggle('hidden', n.dataset[key] !== t.dataset[key]);
});
}
});
data-text="3"
const something = {
Crossfit: "Кросфит",
aerobics: "aerobics",
relax: "relax"
}
<a data-name="Crossfit" data-text="3" ....></a>
<a data-name="aerobics" data-text="3" ....></a>
<a data-name="relax" data-text="3" ...></a>
const name = $(this).attr('data-name');
const currentText = something[name]; // Ваш текст
Библиотеку jquery залил напрямую c google
function my_scripts_method() {
$tpl = get_stylesheet_directory_uri();
wp_enqueue_script('bootstrap', $tpl . '/js/bootstrap.min.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'my_scripts_method');