Note that there are some explanatory texts on larger screens.

plurals
  1. POToggle Show / Hide Untoggle Click Outside
    primarykey
    data
    text
    <p><strong>EDIT:</strong> <em>I tried GLK.net's link but I could not manage to get this to work. It would simply break my function.</em></p> <p>I have a span element where, if you click it, it will toggle a ul (first click = show / second click = hide).</p> <p>I want it so, if the ul is shown, the user should be able to click outside of the element (so, the document / html) to hide the list.</p> <p>Here is my code:</p> <p>btw, the $('hmtl').css('cursor', 'pointer'); is used for iOS.</p> <p>(function($) {</p> <pre><code>$.fn.styledDropdown = function() { var obj = $('#tag-cloud'); obj.find('.field').click(function() { // onclick event, show wp-tag if (obj.find('.wp-tag-cloud').is(':hidden')) { obj.find('.wp-tag-cloud').show(); obj.find('i').attr('class', 'icon-eqtri-up'); $('html').css('cursor', 'pointer'); $(document).keyup(function(event) { // keypress event, hide wp-tag list if(event.keyCode == 27) { obj.find('.wp-tag-cloud').hide(); obj.find('i').attr('class', 'icon-eqtri-down'); $('html').css('cursor', 'default'); } }); } else { obj.find('.wp-tag-cloud').hide(); obj.find('i').attr('class', 'icon-eqtri-down'); $('html').css('cursor', 'default'); } }); obj.find('.wp-tag-cloud li a').click(function() { // onclick event, change field value with selected list item and show list obj.find('.field').html( $(this).html() + '&lt;i class="icon-eqtri-down"&gt;&lt;/i&gt;' ); obj.find('.wp-tag-cloud').hide(); $('html').css('cursor', 'default'); }); }; </code></pre> <p>})(jQuery);</p> <p>Any help with this would be greatly appreciated.</p> <ul> <li>Code has been adapted from an example at css-tricks.com</li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
 

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