www.webdeveloper.com
Results 1 to 5 of 5

Thread: Can we apply javascript events on elements load via ajax?

  1. #1
    Join Date
    Sep 2008
    Posts
    13

    Can we apply javascript events on elements load via ajax?

    Hello,
    I have a question here. Is there any way to apply some javascript behavior fired by an event (click), on elements that have been loaded on page via ajax load()??? How?

    Can you please help me a little with this???

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    element.onclick=function(){somefunction(someraguments)}

  3. #3
    Join Date
    Sep 2008
    Posts
    13
    kor, I know how to use such kind of functions. I have tried to use a "click function" but it's not working because it seems that javascript is not able to "see" these elements that have been loaded with ajax.

    For example if I load a div via ajax and try to add a click behavior on it, it seems that it's not there - it doesnt exist, for javascript.
    Maybe these elements do not belong to DOM and they still remain external data. I don't know.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Well yes. The AJAX response is either a string or an XML object. In both cases you do not have a DOM valid insert. I guess you have used the innerHTML method to write the response to the document. But innerHTML is not a standard DOM method and it does not insert always the elements into the DOM tree.

    I guess you should write the event at the other end of the request, in the server-side application code.

  5. #5
    Join Date
    Mar 2009
    Posts
    467
    How are you loading the DIV from the AJAX response? Is it response text or XML? And what is being done with it? How are you inserting it into the document? You are not providing enough information for anyone to give you a quick explanation.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles