1) Are you sure that $("#dmid img", msg).each() is actually looping
through all the elements you intended to loop through? Instead of
doing a bind, try $(this).hide() to debug it. If it's not hiding the
elements, it's not looping correctly. If it does hide, your event
handler is not working correctly.

2) Is there a reason you're using <imgg... ? It's suppose to be <img
But there are many advantages to using jQuery binding, such as:
- you only code it once.
- you separate code from markup, which keeps your page clean.
If you have a lot of img tags, you might want to consider using Event
Delegation. It lets you bind once to the img's parent element rather
than X number of img tags (which is slow and more browser processer
intensive).


On Mar 14, 6:21 am, ulgold <ulg...@gmail.com> wrote:
> When I try to bind events like within ajax call:
>
> $.ajax({
>                 type: 'POST',
> ...........................
>
>                 success: function(msg) {
>
>                      $("#dmid img", msg).each ( function() {
>
>                      $(this).bind('mouseover', handler)
> ...............................
>
> problem is the event is not bound   unless I do something like:
> $('#firstdiv').html(msg)
> $("#dmid img").each ( function() {
>         $(this).bind('mouseover', handler)
>
> Any idea why we cannot bind events when context is  other than the
> current loaded document?
>
> Another question:
> I have the option of writing onclick events  within HTML page like:
>
> <imgg src=""   onclick=" return  imghandler(event);" >
> <imgg src=""   onclick=" return  imghandler(event);" >
> <imgg src=""   onclick=" return  imghandler(event);" >
>
> or using jquery to bind the onclick events above when the document has
> loaded like
>
> $("imgg").each ( function() {
>         $(this).bind('mouseover', imghandlerr)
>
> }
>
> Apart from the fact that the page size that is transported from the
> server to the client is reduced when using jquery binding of events
> ( due to missing hard coded onclick handlers in html), are there any
> other advantages or disadvantages of either approach?

Reply via email to