Domanda

$pageslide.click(function(e) {
e.stopPropagation();
});

That prevents the #pageslide ID or Class from sliding if clicked, how do i exclude certain elements from being prevented, in this case i want to exclude <a></a> or <li></li>. Thanks in advance .

È stato utile?

Soluzione

.target property of the event object refers to the target of the event, you can read this property:

$pageslide.click(function(e) {
   if ( $.inArray(e.target.localName, ['li', 'a']) < 0 ) {
      e.stopPropagation();
   }
});

Or use .closest() method:

if ( $(e.target).closest('a').length === 0 ) {
   e.stopPropagation();
}

Altri suggerimenti

Use jQuery's filter method.

$pageslide.filter('a li').click(function(e) {
    e.stopPropagation();
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top