0

my image slider code onclick event was not working on android tablet .I am using Jquery lib.when I added following code ,

var clickEventType=((document.ontouchstart!==null)?'click':'touchstart');
$("#myImageFlow").bind(clickEventType, function( e ) {
    $(this).addEventListener( 'touchstart', touchStart, false);
}); 
//custom function handler for event                  
function touchStart(event){
     event.preventDefault();

};

this code make make my slider respond ontouch event but in Inspect console i am getting error

Error::

Uncaught TypeError: Object [object Object] has no method 'addEventListener'

because of this error some of functionality is not working ??

5
  • may be try this : $(this).get(0).addEventListener( 'touchstart', touchStart, false); Commented Jun 13, 2013 at 12:21
  • 1
    Why are you trying to add an event listener from inside another event handler? The .bind(clickEventType... code may (depending on the preceding line) have just added a 'touchstart' handler, and then you're trying to add another?
    – nnnnnn
    Commented Jun 13, 2013 at 12:23
  • @nnnnnn my image slider onclick was not working on android tab so i tried adding this way. .bind() only works if i alert something ..
    – anam
    Commented Jun 13, 2013 at 12:27
  • @Cherniv i tried ur suggestion not working ,
    – anam
    Commented Jun 13, 2013 at 12:29
  • @alex my question !!!!
    – anam
    Commented Jun 13, 2013 at 12:42

1 Answer 1

0

use .on()

$(this).on('touchstart', touchStart);

you are getting that error because .addEventListener is not a jquery method

1
  • 2
    @pXL just wanted to know, inside .on(a, b, c), first parameter a is for the event, second b is for the handler, what is the third parameter c for?? In your case false??
    – palaѕн
    Commented Jun 13, 2013 at 12:29

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.