×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    12

    jQuery's click event not getting registered

    Hi all,

    I am trying to generate and load a table dynamically into a container div as follows -

    Code:
    	loadTable = function(data){
    		var table_str = '';
    		for(var i=0;i<data.matches.length;i++){
    			table_str += '<table border="0" cellspacing="0" cellpadding="0" class="mtch_table" id="abc"><tr><th colspan="2" scope="col"><div class="left_align upcase game-mins"></div></th><th><div class="right_align"><a href="#"></a></div></th></tr><tr><td>'+data.matches[i].awteam.name+'</td><td><div class="right_align"></div></td></tr><tr><td>'+data.matches[i].hmteam.name+'</td><td><div class="right_align"></div></td></tr></table>';
    			table_str += '<hr>';
    		}
    		$('.table_container').html(table_str);
    	};
    	$('.mtch_table').click(function(){
    		console.log($(this));
    	});

    and the HTML -
    Code:
    			<div class="table_container">
    				MATCHES
    			</div>
    jQuery's click event is not getting registered on the table mtch_table as shown in the above code. However, it is working fine if I use the enclosing div table_container instead of the table mtch_table...

    What could be the reason for this? Is there any way to register click on the table mtch_table?

    Thanks,
    Anujit

  2. #2
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: jQuery's click event not getting registered

    Only reason I could think of right now is that .mtch_table doesn't exist when you are trying to bind an event listener. So you could double check code execution order or perhaps try to bind events via delegate function. It must be also noted that javascript doesn't always work as expected in S40 web apps.

  3. #3
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Re: jQuery's click event not getting registered

    And you should try to not rely on jQuery, since it often behaves unexpected in a Series40 WebApp. Try using directly onclick="...".

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    12

    Re: jQuery's click event not getting registered

    Quote Originally Posted by mikkovtr View Post
    Only reason I could think of right now is that .mtch_table doesn't exist when you are trying to bind an event listener. So you could double check code execution order or perhaps try to bind events via delegate function. It must be also noted that javascript doesn't always work as expected in S40 web apps.
    Thanks mikkovtr... Delegate function does the trick! I am using .on() and its running as expected!!

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    12

    Re: jQuery's click event not getting registered

    Quote Originally Posted by lorion84 View Post
    And you should try to not rely on jQuery, since it often behaves unexpected in a Series40 WebApp. Try using directly onclick="...".
    thanks lorion84, using onclick='....' inline is working as desired as well..

Similar Threads

  1. Touch/Click event over QVideoWidget
    By roguel6 in forum Qt
    Replies: 4
    Last Post: 2011-01-21, 15:46
  2. Replies: 2
    Last Post: 2010-10-19, 08:06
  3. jQuery click() events not working in WRT
    By bryanrieger in forum Symbian
    Replies: 5
    Last Post: 2010-05-19, 14:44
  4. Mouse click Event
    By abhimanyu1 in forum Symbian
    Replies: 2
    Last Post: 2009-10-09, 08:10
  5. Camera Click Event
    By shashideokar10 in forum Symbian
    Replies: 1
    Last Post: 2008-06-10, 09:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×