SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    not sure if i am using a callback correctly

    Can a callback be used as a parameter of any function? Right now I am not getting an alert after the textarea receives focus..

    Code JavaScript:
    $('#frmContact textarea').focus(function(){
    		$(this).removeClass('dimtext').val('', function(){
    			alert('ok');
    		});
    	});

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can only use a callback for functions which are designed for one.

  3. #3
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a list somewhere of functions designed to accept callbacks? I did some searches but didn't find anything..

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if someone has created a list of all the functions which accept a callback, and I don't think many people would need such a list. I'm starting to think maybe you're confused about why/when a callback is needed. What made you think you should be using a callback?

    Individual functions are documented, and it's always specified if they accept a callback.

    In your example, there's really no need for a callback other than the focus event handler. removeClass() and val() are synchronous operations, and you're probably operating on a single element, so I don't even see the need for using a callback.
    Code:
    $('#frmContact textarea').focus(function(){
        $(this).removeClass('dimtext').val('');
        alert('ok');
    });


Bookmarks

Posting Permissions

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