Facing issue with a toggle component




I have created a footer component that shows n number of links and hides all the other with a show hide button to show the remaining links based on user click. The first component authored works fine but the rest of the components authored are not responsive at all and the toggle functionality fails to work if the same component is authored multiple times on the page.

Please find the below sample code of the component:

HTML Code:

<div data-sly-test="${wcmmode.edit}" data-sly-unwrap>
<div data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}" data-sly-unwrap>
<clientlib data-sly-call="${clientLib.all @ categories=['author.widget.multifieldpanel']}" data-sly-unwrap/>
<div class="outer">
<div class="title" id="alen">${properties.mtitle}</div>
<div data-sly-use.myClass="${'com.utilities.widgets.Multifield' }" data-sly-unwrap>
<div data-sly-list="${myClass.myHashMap}" data-sly-unwrap>

<div data-sly-test="${itemList.count <= 6}">
<a id="alink " value=" ${itemList.count}" class="link" href="${item['linkpath']}">${item['title'] @ context="html"}</a>
<div data-sly-test="${itemList.count > 6}">
<a id="alink" value=" ${itemList.count}" class="link hide-more" href="${item['linkpath']}">${item['title'] @ context="html"}</a>

<sly data-sly-test="${properties.multitotal}">
<div class="link-toggle" id="moreli" >See More</div>
<div class="link-toggle expand-option" id="lessli" >See Less</div>


$("#moreli").click(function() {
$("#moreli").css("display", "none");
$("#lessli").css("display", "block");
$(".hide-more").css("display", "block");

$("#lessli").css("display", "none")
$("#moreli").css("display", "block");
$(".hide-more").css("display", "none");

Accepted Solutions (1)

Accepted Solutions (1)




Javscript logic is wrong -

It should be like

$("#moreli").click(function() {
$( this ).css("display", "none");
$( this ).sinbling("#lessli").css("display", "block");
$( this ).sinbling(".hide-more").css("display", "block");

 Above cpde is just for reference, please implement logic based on current(this) object to deal with individual instance. 

Answers (0)