1

I'm working on a website currently created in AngularJS. I do NOT have access to the backend where the code exists. I need to develop a script to make changes to that page using CSS, Javascript, or JQuery. One of those changes involves creating a new element. Once the user clicks on that element(mobile users will use touchstart not click) it will need to trigger a click event on an existing element on the page.

        $('.DatePicker').on('click touchstart touch',function(){
            //on click of element, sim click on the bau date to pop open datepicker
            console.log('datepicker clicked');
            $('input#dateMobile').trigger('touchstart');
        });

This is what I currently have. I can get the console log to appear but the trigger on the element will not work regardless if I use click, touch, touchstart, touchend.

That is the current html of the element i'm trying to trigger click on :

<input type="date" id="dateMobile" class="payment-date__input ng-valid-min ng-valid-max ng-valid-v-date ng-valid-v-date-min ng-valid-v-date-max ng-valid-v-date-format ng-dirty ng-valid-date ng-valid ng-valid-required ng-touched" name="dateMobile" friendly-date="" validate-date-range="" 
    ng-if="isMobile.any" min="2017-02-03" max="2017-04-04" 
    ng-model="dateModelMobile" 
    ng-blur="updateDate('dateModelMobile')" 
    ng-change="updateDate('dateModelMobile')" required="" aria-required="false" aria-invalid="false">
8
  • 1
    what is your html view ? you should not use jquery manipulate the dom, example <button ng-click="orderDate()">order</button> and in scope $scope.orderDate = function(){... } Commented Feb 3, 2017 at 16:57
  • There is no ng-click on the element i'm trying to trigger click on. I do not know the $scope either because i have no access to that element. I have no choice but to use jquery or javascript to edit this page. There's no other way around it. Commented Feb 3, 2017 at 17:06
  • <input type="date" id="dateMobile" class="payment-date__input ng-valid-min ng-valid-max ng-valid-v-date ng-valid-v-date-min ng-valid-v-date-max ng-valid-v-date-format ng-dirty ng-valid-date ng-valid ng-valid-required ng-touched" name="dateMobile" friendly-date="" validate-date-range="" ng-if="isMobile.any" min="2017-02-03" max="2017-04-04" ng-model="dateModelMobile" ng-blur="updateDate('dateModelMobile')" ng-change="updateDate('dateModelMobile')" required="" aria-required="false" aria-invalid="false"> that is the current html of the element i'm trying to trigger click on Commented Feb 3, 2017 at 17:08
  • according to your html you already have a function called when the input is changed : updateDate(). you can add your code in this function in the controller Commented Feb 3, 2017 at 17:47
  • 1
    Angular is NOT a backend framework. It is 100% front end. It is also a javascript library. So, when you say you can only use jQuery or Javascript(which Angular absolutely is), and NOT Angular, that is very confusing Commented Feb 3, 2017 at 22:01

0

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.