Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to click the nearest anchor when my custom checkbox is toggled
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/W8HRk.png" alt="Faceted search with Custom Checkbox"> </p> <p>HTML</p> <pre><code>&lt;li class="leaf"&gt; // The span is my custom checkbox that wraps around the default checkbox. &lt;span class="checkbox facetapi-checkbox checked"&gt; // The span above replaces the default checkbox below, which you'll notice has a display:none; I don't want both checkboxes showing. &lt;input type="checkbox" class="facetapi-checkbox" checked="true" style="display: none; "&gt; &lt;/span&gt; // This is the anchor tag that I need to click when my custom checkbox is checked. // It's outside of my custom checkbox span, but shares the same parent. &lt;a href="/part-finder/field_rep_catalog/heater-1527" rel="nofollow" class="facetapi-active facetapi-checkbox-processed" style="display: none; "&gt;(-) &lt;span class="element-invisible"&gt;Remove Support filter&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; </code></pre> <p>Here is the jQuery used to replace the default checkbox with my custom one: </p> <pre><code>//Checkbox Image Replacement $('.faceted_search_column input[type=checkbox]').each(function() { var span = $('&lt;span class="' + $(this).attr('type') + ' ' + $(this).attr('class') + '"&gt;&lt;/span&gt;').click(doCheck).mousedown(doDown).mouseup(doUp); if ($(this).is(':checked')) { span.addClass('checked'); } $(this).wrap(span).hide(); }); // You'll notice that when this function is run, I've attempted to use .closest() to find the nearest anchor and then do a .triggerHandler('click') to click that anchor it finds. This obviously didn't work. Should I use .parent() to move back in the DOM? function doCheck() { if ($(this).hasClass('checked')) { // This was my attempt to click the anchor when doCheck function is run. $(this).closest('a.facetapi-checkbox-processed').triggerHandler('click'); $(this).removeClass('checked'); $(this).children().prop("checked", false); } else { $(this).parents('a.facetapi-checkbox-processed').triggerHandler('click'); $(this).addClass('checked'); $(this).children().prop("checked", true); } } function doDown() { $(this).addClass('clicked'); } function doUp() { $(this).removeClass('clicked'); } </code></pre> <p>What do you guys recommend as the most efficient way to trigger that anchor click when the user toggles the checkbox? It's a faceted search anchor, so I need both checked or unchecked to trigger the same anchor tag. </p> <p>Thanks in advance for those who take the time to help me out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload