2

I'm currently using element.trigger('click') to simulate a regular click, but how could I, using angular simulate a SHIFT-click?

4
  • Trigger a key down event for the shift, the click event, a key up event for the shift Commented Jul 2, 2015 at 21:46
  • element.trigger('click') doesn't actually "click" anything... It executes the click handler Javascript function for the element. Commented Jul 2, 2015 at 21:46
  • @PaulS: Note that a real shift-click doesn't require that the element already have the focus. Commented Jul 2, 2015 at 21:48
  • related: stackoverflow.com/questions/1165222 Commented Jul 2, 2015 at 21:49

2 Answers 2

2

To anyone looking for the answer:

var clickEvent = $.Event('click');
clickEvent.shiftKey = event.shiftKey;
element.trigger(clickEvent);

Thanks to all that responded.

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

1 Comment

Just for reference, this uses JQuery so it's not something you can do with just Angular (or vanilla JS).
0

I know this is old, but if anybody is looking for an updated Angular solution:

const trs: NodeListOf<HTMLTableRowElement> nativeElement.querySelectorAll("tbody > tr");

const ev = new MouseEvent("click", { shiftKey: true });
trs[3].dispatchEvent(ev)

This will shift-click on the third table body row...

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.