Trying to decipher the intricacies of this JQuery
code has been quite the challenge for me. I would normally opt for a different approach, but it seems I must adhere to this particular method. My main issue lies in getting the functionality right - when clicking on the plus
symbol, content should expand and the symbol should change to a minus
symbol with a color change. The expanding part works fine, but the collapsing doesn't quite function as intended. Additionally, the use of Sass
in this project has me stumped, particularly the &.expanded
syntax. What exactly does it signify? I've combed through the HTML but can't seem to locate a class named expanded
, yet it's referenced in the JQuery code within the _Layout file.
Unclear JQuery
function ($(".contact_item.expanded")
?? What does this signify?):
<script>
/* expand */
$(".contact_item .head").click(function () {
$('.contact_item.expanded .head').next('div').slideUp();
$('.contact_item.expanded').removeClass('expanded');
$(this).parent('div').toggleClass('expanded');
$(this).next('div').slideDown();
});
</script>
The perplexing Sass
code snippet featuring the enigmatic &
symbol:
.contact_item {
width: 100%;
border: 1px solid #f1e7e0;
background-color: #fcf6f5;
margin: 3px 0px;
float: left;
&.expanded {
.head .name {
color: #f60;
}
.head .name span {
border-color: #f60;
color: #f60;
&.plus {
display: none;
}
&.minus {
display: block;
}
}
}
.head {
.name {
font-family: "Tahoma";
color: rgb(100, 100, 100);
font-size: 11.1px;
text-transform: uppercase;
padding: 7px 15px;
cursor: pointer;
position: relative;
span {
position: absolute;
display: block;
width: 20px;
height: 20px;
border-radius: 50%;
border: 1px solid #706f6f;
text-align: center;
right: 15px;
top: 7px;
font-size: 18px;
line-height: 17px;
&.minus {
display: none;
}
}
}
}
}
It's evident in this image that the CALIFORNIA OFFICE
section is expanded, but the collapse and expand behavior of clicking the minus
symbol is glitchy...
https://i.sstatic.net/yPC6N.png
UPDATE
Using the F12 tool to inspect the HTML, it's clear that <div class="contact_item">
transitions to
<div class="contact_item expanded">
, but this transformation isn't reflected in Razor:
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
@{ var locations = LocationLookup.GetLocations(); }
@{ int numloc = locations.Count / 2;}
@{ var newlist = locations.Take(numloc);}
@foreach (var loc in newlist)
{
<div class="contact_item ">
<div class="head">
<div class="name">@loc.Name office<span class="plus">+</span> <span class="minus">-</span></div>
</div>
<div class="info">
<ul>
<li>
<div class="icon"><img src="//lig.azureedge.net/public/UK/Content/Images/marker.png" alt=""></div>
@loc.Address @loc.Continued, @loc.City, @loc.PostCode, @loc.State
</li>
<li>
<div class="icon"><img src="//lig.azureedge.net/public/UK/Content/Images/phone.png" alt=""></div>
@loc.Phone
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
}
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
@for (int i = numloc; i < locations.Count; i++)
{
<div class="contact_item ">
<div class="head">
<div class="name">@locations[i].Name office<span class="plus">+</span> <span class="minus">-</span></div>
</div>
<div class="info">
<ul>
<li>
<div class="icon"><img src="//lig.azureedge.net/public/UK/Content/Images/marker.png" alt=""></div>
@locations[i].Address @locations[i].Continued, @locations[i].City, @locations[i].PostCode, @locations[i].State
</li>
<li>
<div class="icon"><img src="//lig.azureedge.net/public/UK/Content/Images/phone.png" alt=""></div>
@locations[i].Phone
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
}
</div>
</div>
</div>
This is the HTML code as displayed using the F12 tool in the browser, showcasing the structure within <section class="hidden-print" id="contact"> and the dynamic changes occurring with the <div class="contact_item"> sections.