Answer the question
In order to leave comments, you need to log in
How to set up wireless access to Raspberry Pi Zero W via Bluetooth?
Raspbian Lite installed. How to access the raspberry terminal using the built-in bluetooth module?
Answer the question
In order to leave comments, you need to log in
The logic is not clear, but the code can be simplified like this:
var tRish = "tits_rish_a1 tits_rish_a2 tits_rish_a3";
var tRishClasses = tRish.split(' ').map(e=>'.' + e).join(', '); // список классов .tits_rish_a1, .tits_rish...
var tClick = "#tits_click_a1, #tits_click_a2, #tits_click_a3";
$(function() {
function onClick(e) {
var n = (n = this.id.match(/b(\d+)/)) ? n[1] : null; // n == 1, 2 или 3
if(!n) return;
$(tClick).removeClass(tRish).addClass( 'tits_rish_a' + n);
// $(tClick).attr('id', 'tits_click_a' + n); // id менять некошерно!
$(tRishClasses).attr('style', '');
}
$('#b1, #b2, #b3').on('click', onClick);
});
#b2 => 2
and then uses the resulting number to compose the classes/id.
Without HTML, it is unlikely that you will understand what you want to do at all. You get 3, formally, identical blocks (judging by the ID), to which, formally, 3 identical classes are applied. Why don't you just make ONE CLASS to which ONE class applies? And in CSS through: nth-child already specify styles for different positions of this class?
Hello, I am superficially familiar with js and jq. What's more, I can't tell them apart.
how to shorten itMost likely, all your code can be replaced with something in 10 lines (one handler on the parent element, changing the class instead of changing the id), but I don’t quite understand what you are trying to do, and therefore I can’t tell you exactly how to change it.
Your code does not make sense, you change the id of the elements, set the same for several elements at once, which cannot be done (formally it will work, but not as it should).
About shorthand - you can pass multiple selectors to jQuery:
$("#tits_click_a1, #tits_click_a2, #tits_click_a3")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question