I have Lightning Component and I want to Show/Hide Multiple Div using Aura:ID. Currently, am doing this:
Lightning Component
<div class="chat_invitation" id="">
<div class="chat-headline">
<span class="chat-toggle show"><i id="icon1" class="{!v.toggleIcon}" aria-hidden="true" onclick="{!c.toggleButton}"></i></span>
</div>
<div class="chat-text" aura:id="toggle1">
<p>hi</p>
</div>
<div class="chat-start" aura:id="toggle2">
<iframe src="A URL" style="height: 40px; margin-left: 4px;" />
</div>
<div class="chat-call" aura:id="toggle3">
<p> <span class="number">PHONE NO.</span></p>
</div>
<div class="chat-support" aura:id="toggle4">
<p>Need customer support? <a href='URL' target='_blank'>Click here</a>.</p>
</div>
</div>
Controller:
toggleButton : function(component, event, helper) {
var label = component.get("v.toggleIcon");
if(label == 'fa fa-chevron-down'){
component.set("v.toggleIcon","fa fa-chevron-up");
$A.util.addClass(component.find("toggle1"), "toggle");
$A.util.addClass(component.find("toggle2"), "toggle");
$A.util.addClass(component.find("toggle3"), "toggle");
$A.util.addClass(component.find("toggle4"), "toggle");
}else {
component.set("v.toggleIcon","fa fa-chevron-down");
$A.util.removeClass(component.find("toggle1"), "toggle");
$A.util.removeClass(component.find("toggle2"), "toggle");
$A.util.removeClass(component.find("toggle3"), "toggle");
$A.util.removeClass(component.find("toggle4"), "toggle");
}
}
CSS:
.THIS .toggle {
display: none;
}
The thing is, this is not the best way to do this. Any direction would be great. TIA.