Question

$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 .

Était-ce utile?

La solution

.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();
}

Autres conseils

Use jQuery's filter method.

$pageslide.filter('a li').click(function(e) {
    e.stopPropagation();
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top