views:

154

answers:

2

I have a page in which i can successfully use the jquery focus function using live...

$(".comment_text_class").live('focus',
function() {
   //do something...
});

but when something comes into the page(ajax loading) the focus function doesn't work

as should be using the live function...

as suggested i used focusin function..

$(".comment_text_class").live('focusin',
function() {
   //do something...
});

but still new elements do not have the behavior...

also i want to hide something using the live function but it doesn't work at all..

even for the elements in the page itself...

   $(".comment_button").live('hide', function(){});

is the focus and hide function implemented at all by jquery 1.4.2 or is it a bug...
because the live focus was not working with jquery 1.4 version...

well the page here... http://pradyut.dyndns.org/WebApplicationSecurity/newuser.jsp?id=2

sorry .. fixed it out...

Please help...

thanks

Pradyut
India

A: 

As of jQuery 1.4.1, the focus event works with live handlers. See http://api.jquery.com/live/ for more info.

mikez302
+1  A: 

.live() doesn't work like you think I believe. It doesn't watch for new elements and execute code, rather it waits or events to bubble up and acts upon them if the trigger element matches the selector.

.live('focus') and .live('blur') work in jQuery 1.4.1+, however you could use the focusin and focusout events in 1.4.0.

As for the hide, that's not an event. If you're hiding all comments as soon as they're added, it seems like CSS is a better approach, like this:

.comment_button { display: none; }

Alternatively you can use the .livequery() plugin like this:

$(".comment_button").livequery(function(){ $(this).hide(); });
Nick Craver
ok i used focusin and still new elements do not have the behaviour...
Pradyut Bhattacharya
@Pradyut - Can you post your ajax code? Something else seems to be interfering here.
Nick Craver
well the page here...http://pradyut.dyndns.org/WebApplicationSecurity/newuser.jsp?id=2login using userid:[email protected] and password:12345and then the shouts tab...
Pradyut Bhattacharya
thanks Nick Craver.. fixed it out...
Pradyut Bhattacharya