Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm the author of enquire.js, so hopefully I'll be able to help you ;-)</p> <p>Basically, you want to add an event handler on match and remove event handler on unmatch. You seem to have the gist of how to do this above, but you've got the syntax a little wrong. Once the syntax is corrected it's just some jQuery knowledge to remove the click handler.</p> <p>So let's look at how the syntax should be:</p> <pre><code>enquire.register("screen and (max-width:500px)", { match: function() { //match code here }, unmatch: function() { //unmatch code here } }).listen(); </code></pre> <p>Notice that match and unmatch are part of a single object supplied to <code>register</code>.</p> <p>Ideally you should be putting this in your document ready callback. To assign your click handler use jQuery's <code>on</code> method, as this allows you to use the <code>off</code> method to unassign:</p> <pre><code>$(".block .block-title").on("click", function() { alert("hello"); }); $(".block .block-title").off("click"); </code></pre> <p>This is great because you can even namespace your events, read up on the jQuery docs for more details on this. So to put it all together, we would have this:</p> <pre><code>$(document).ready(function() { var $target = $(".block .block-title"); enquire.register("screen and (max-width:500px)", { match: function() { $target.on("click", function() { alert("Hello World!"); }); }, unmatch: function() { $target.off("click"); } }).listen(); });​ </code></pre> <p>You can find a working example here: <a href="http://jsfiddle.net/WickyNilliams/EHKQj/" rel="noreferrer">http://jsfiddle.net/WickyNilliams/EHKQj/</a></p> <p>That should then be all you need :) Hope that helps!</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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