0

Having a link with data-filter="*" I fail to trigger the clicking of the link by

jQuery("a [data-filter='*']").trigger("click");

How can this be done correctly?

https://jsfiddle.net/yefjsmwf/

2
  • Spaces in a selector denote child selectors. If you want a logical AND conditional, remove the space. Commented Aug 23, 2017 at 16:12
  • All your issues are typo related. Spaces in the wrong spots as Taplar noted, and incorrect function syntax. jsfiddle.net/j08691/ndLvs2yd. Your question should also include a minimal reproducible example. Don't ask us to visit a third-party site for a complete example when there's no reason for you not to post it in your question. Commented Aug 23, 2017 at 16:14

1 Answer 1

1

Changed your js code :

jQuery("a[data-filter='*']").click(function() {
	jQuery("#other").css("color", "green");
});

jQuery("a[data-filter='*']").trigger("click");
a {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a href="#" data-filter="*">Past and Upcoming Events</a>
<a href="#" data-filter="Past">Past Events</a>
<a id="other" href="#">some other link</a>

Hope, this works for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.