1

I am writing a tampermonkey script on chrome to simulate a mouse click and find that only document.getElementById('id').click() trigger the correct behaviour.

The expected behaviour is to show and hide a date-picker. With $('#id').trigger('click') I can only hide the date-picker. I do not think I should add more details because that may just add more confusion.

The page is Telerik based, so I have not found an easy way to simplify the page and isolate the issue.

Update:

Here is the DOM code

<a title="Open the calendar popup." href="#" id="id" class="rcCalPopup">
    Open the calendar popup.
</a>

After reading this and this, it looks like a or the content of a is causing this issue.

This is all about what you are clicking and it is not the tag but the thing within it. Unfortunately, bare text does not seem to be recognised by JQuery, but it is by vanilla javascript.

Can anyone help confirm this?

Update 2:

I have created a jsfiddle here. It is not ideal, because I have to add dependency of Telerik to reproduce the issue.

    setTimeout(function () {
        $('#id')[0].click(); // Show the date-picker
        document.getElementById('id').click(); // Hide the date-picker
        $('#id').trigger('click'); // Not working, should show the date-picker again. Tried for <button> and it worked fine.
}, 1000);
Community
  • 1
  • 1
Devs love ZenUML
  • 11,344
  • 8
  • 53
  • 67
  • 1
    You need to post all the code relative to this mysterious `#id`. For all we know the error is just a simple syntax problem (not to insult you or your coding capabilities), so we need to see _all_ the relevant code. – kairocks2002 Mar 14 '16 at 23:57
  • `$('#id').trigger('click')` seems to work as expected see http://jsfiddle.net/DelightedDoD/jjcsh76w/1/ . You're question is about *how to show and hide a date-picker using $('#id').trigger('click')* but you dont show us any of that code. Youll need to show us the datepicker code or make a jsfiddle so we can see the issue. \ – Wesley Smith Mar 15 '16 at 00:25
  • Hi @DelightedD0D, my question is about the difference between `trigger('click')` and `click()`. That is way I am reluctant to add more unrelated details. I have managed to solve the problem of showing the date-picker, but wonder why one solution did not work. – Devs love ZenUML Mar 15 '16 at 00:28
  • Sure, but if we dont see the issue, it's going to be hard to explain it, right? This could well be an [X Y problem](http://xyproblem.info/) , context matters – Wesley Smith Mar 15 '16 at 00:30
  • Thanks @DelightedD0D. I have created a jsfiddle and updated the question. – Devs love ZenUML Mar 15 '16 at 23:53

0 Answers0