Я хочу создать структуру, как показано на изображении ниже, с неупорядоченным элементом списка, если пользователь щелкнет элемент списка, круг должен заполниться цветом. Я создал в div, внутри которого я взял элементы списка и внутри элемента диапазона списка.Я пользователь нажимает на первый элемент списка, круг должен заполняться цветом, если я нажимаю на другой список, он должен заполняться цветом, как активный, или фокусироваться на ссылках в строке меню
Вот чего я должен достичь Вот чего я хочу достичь
Вот что я пробовал
<div class = "sizes">
<ul>
<li class = "dot"><span></span>6"x6" | 599</li>
<li class = "dot"><span></span>12"x12" | 799</li>
<li class = "dot"><span></span>12"x18" | 999</li>
<li class = "dot"><span></span>18"x12" | 799</li>
<li class = "dot"><span></span>16"x20" | 1,399</li>
</ul>
</div>
css
.shop-all .product-content ul li {
position:relative;
font-family: 'Lato';
font-size: 16px;
font-weight: bold;
padding: 10px 0 10px 0;
cursor: pointer;}
.shop-all .product-content ul li span {
border-radius: 50%;
border: 1px solid #d95d5d;
padding: 2px 10px;
margin-right: 10px;
background-color:#fff;
}
.shop-all .product-content ul li span.filled {
background-color: #d95d5d;
}
.shop-all .product-content ul li span:before{
content:'';
position:absolute;
border-left:1px solid #d95d5d;
top:10px;
z-index: -1;
height: 92%;
}
.shop-all .product-content ul li:last-child span:before{
content:none;
}
.shop-all .product-content ul li:last-child{
padding-bottom:0
}
.shop-all .product-content ul {
list-style: none;
}
jquery
$('.dot').on('click', function(){
$(this).toggleClass('filled');
});



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Поскольку вы создали класс filled для диапазона, вам нужно попробовать следующий способ. Так что измени
$('.dot').on('click', function(){
$(this).toggleClass('filled');
});
К
$('.dot').on('click', function(){
$('.dot').find('span').removeClass('filled');
$(this).find('span').toggleClass('filled');
});
спасибо за помощь, но если вы хотите удалить этот заполненный класс из текущего элемента и переместить его в другой список, который сейчас нажат
@ScottSauyet, извините, я не знаком с этим.
@Kiranramchandran: см. Этот мета-ответ для получения дополнительной информации: meta.stackoverflow.com/questions/358992
Здесь вам нужно добавить класс в html согласно css и использовать ниже jquery
$('.dot').on('click', function(){
$('.dot').children('span').removeClass('filled');
$(this).children('span').toggleClass('filled');
});.shop-all .product-content ul li {
position:relative;
font-family: 'Lato';
font-size: 16px;
font-weight: bold;
padding: 10px 0 10px 0;
cursor: pointer;}
.shop-all .product-content ul li span {
border-radius: 50%;
border: 1px solid #d95d5d;
padding: 2px 10px;
margin-right: 10px;
background-color:#fff;
}
.shop-all .product-content ul li span.filled {
background-color: #d95d5d;
}
.shop-all .product-content ul li span:before{
content:'';
position:absolute;
border-left:1px solid #d95d5d;
top:10px;
z-index: -1;
height: 92%;
}
.shop-all .product-content ul li:last-child span:before{
content:none;
}
.shop-all .product-content ul li:last-child{
padding-bottom:0
}
.shop-all .product-content ul {
list-style: none;
}<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class = "shop-all">
<div class = "product-content">
<ul>
<li class = "dot"><span></span>6"x6" | 599</li>
<li class = "dot"><span></span>12"x12" | 799</li>
<li class = "dot"><span></span>12"x18" | 999</li>
<li class = "dot"><span></span>18"x12" | 799</li>
<li class = "dot"><span></span>16"x20" | 1,399</li>
</ul>
</div>
</div>jQuery("li").click(function() {
jQuery(this).toggleClass("active");
jQuery(this).siblings().removeClass("active");
});body { margin:0; padding:0;}
.container {
width: 600px;
}
.shop-all .product-content ul li {
position:relative;
font-family: 'Lato';
font-size: 16px;
font-weight: bold;
padding: 10px 0 10px 0;
cursor: pointer; line-height:16px;}
.shop-all .product-content ul li span {
border-radius: 50%;
border: 1px solid #d95d5d;
padding: 0 10px;
margin-right: 10px;
background-color:#fff;
}
.shop-all .product-content ul li.active span {
background-color: #d95d5d;
}
.shop-all .product-content ul li.active { color: #d95d5d;}
.shop-all .product-content ul li span:before{
content:'';
position:absolute;
border-left:1px solid #d95d5d;
top:10px;
z-index: -1;
height: 92%;
}
.shop-all .product-content ul li:last-child span:before{
content:none;
}
.shop-all .product-content ul li:last-child{
padding-bottom:0
}
.shop-all .product-content ul {
list-style: none;
}<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "container">
<div class = "shop-all">
<div class = "product-content">
<ul>
<li class = "dot"><span></span>6"x6" | 599</li>
<li class = "dot"><span></span>12"x12" | 799</li>
<li class = "dot"><span></span>12"x18" | 999</li>
<li class = "dot"><span></span>18"x12" | 799</li>
<li class = "dot"><span></span>16"x20" | 1,399</li>
</ul>
</div>
</div>
</div>Попробуй это..
$('.dot').on('click', function(){
$(this).toggleClass("filled");
$(this).siblings().removeClass("filled");
}); body { margin:0; padding:0;}
.container {width: 600px;}
.shop-all .product-content ul li {
position:relative;
font-family: 'Lato';
font-size: 16px;
font-weight: bold;
padding: 10px 0 10px 0;
cursor: pointer; line-height:16px;}
.shop-all .product-content ul li span {
border-radius: 50%;
border: 1px solid #d95d5d;
padding: 0 10px;
margin-right: 10px;
background-color:#fff;
}
.shop-all .product-content ul li.filled span {
background-color: #d95d5d;
}
.shop-all .product-content ul li span:before{
content:'';
position:absolute;
border-left:1px solid #d95d5d;
top:10px;
z-index: -1;
height: 92%;
}
.shop-all .product-content ul li:last-child span:before{
content:none;
}
.shop-all .product-content ul li:last-child{
padding-bottom:0
}
.shop-all .product-content ul {
list-style: none;
}<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "shop-all">
<div class = "product-content">
<ul>
<li class = "dot"><span></span>6"x6" | 599</li>
<li class = "dot"><span></span>12"x12" | 799</li>
<li class = "dot"><span></span>12"x18" | 999</li>
<li class = "dot"><span></span>18"x12" | 799</li>
<li class = "dot"><span></span>16"x20" | 1,399</li>
</ul>
</div>
</div>
Пожалуйста, используйте StackSnippets для демонстраций HTML / CSS / JS.