tags:

views:

92

answers:

4
+1  A: 

If I understand your question properly, what's wrong with your code is that it's expecting the onchange event on a p to get called. This isn't a thing that normally happens. You should probably read up on onchange and compare/contrast it with whatever behavior you're expecting (which I don't really understand).

chaos
Expected behavior is for error div to remain visible when content is added inside it on error.
dhaval
+1  A: 

It looks like you're setting the <p> to be displayed when it is changed. Why would the <p> be changing? By the way, the #error element is being hidden, so setting the <p> to display isn't going to do anything if its parent is hidden. I think you might need an .end() in there to revert back to the #error element.

I think this is more in line with what you want:

$('#error').hide(); 
$('#error').find('p').change(function(){
        if($(this).contents().length > 0){
                $(this).parent().show();    // .parent() should return #error
        }
});
Andrew Noyes
tried both $('#error').find('p').end().change() and $('#error').find('p').andSelf().change(), it shows for a while and then gets hidden.
dhaval
That won't work because you're setting the change event to both. Try the code above.
Andrew Noyes
Even if you assign change event to the #error and the p elements, there is no reason for the elements to 'disappear'. Something else is going on here.
SolutionYogi
I end and and self in mutually exclusive state ie., when one one used the other was not, The disappearing act is continuing with code too
dhaval
+2  A: 

AFAIK, the change event works only for the input elements, it wouldn't fire for your paragraph element.

EDIT: If your problem is that the paragraphs become invisible again, then there must be some other code which does that. Check for setInternal or setTimeout method calls in your code.

SolutionYogi
there are none , i have also checked on pages where there are no external js got is getting loaded in end
dhaval
A: 

There is no JavaScript error in your code. The issue is that you are hidding the error div. Find is a traversing method that looks to all children of a div. And then you choose to show a div in with a hidden parent. It will not show anything.

Elzo Valugi
I would have left the problem if it dint show but it's visible for a sec and then goes
dhaval
this is probably an internal mecanism of browser redraw. It detects that you call a show but later check the parent and hides again
Elzo Valugi