1

Trying to make this work but seems not having any effect... What am I doing wrong?

With help from @Shyam I got the following working solution:

<div id="narrow-by-list">
    <?php $_filters = $this->getFilters() ?>
    <?php foreach ($_filters as $_filter): ?>
    <?php if($_filter->getItemsCount()): ?>
    <a href="javascript:void(0)">
        <div class="widget <?php echo strtolower($this->__($_filter->getName())) ?>">
            <div class="block-title">
                <h3 class="section-title heading">
                <?php echo $this->__($_filter->getName()) ?></h3>
            </div>
            <div class="widget-content block-content"><?php echo $_filter->getHtml() ?></div>
        </div>
    </a>
    <?php endif; ?>
    <?php endforeach; ?>
</div>
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#narrow-by-list .widget-content").hide();
        jQuery("#narrow-by-list a").click(function(){
            jQuery("#narrow-by-list .widget-content:visible").slideUp("fast");
            jQuery(this).next(".widget-content").slideToggle("fast");
            return false;
        });
    });
</script>

1 Answer 1

1

In your jQuery code, you're using child selector ( > ) which only selects immediate children.

And in your HTML, .widget-content div is not immediate child of parent #narrow-by-list div.

Please try below jQuery code.

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#narrow-by-list .widget-content").hide();
    jQuery("#narrow-by-list .blocktitle").click(function(){
        jQuery("#narrow-by-list .widget-content:visible").slideUp("fast");
        jQuery(this).next(".widget-content").slideToggle("fast");
        return false;
    });
});
</script>

I hope it will help..

2
  • Edited post with your solution, added some more to it to make it work completely.
    – Sebastiaan
    Oct 19, 2016 at 13:26
  • do you also know how to make it close again when you click on the same div? Now you have to click on a different blocktitle to make the other one close; but can the script also be changed so you're able to close the one thats open?
    – Sebastiaan
    Oct 27, 2016 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.