/    Sign up×
Community /Pin to ProfileBookmark

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???

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 30.2009 — <i>
</i>[I]element[/I].onclick=[B]function(){[/B]somefunction(someraguments)[B]}[/B]
Copy linkTweet thisAlerts:
@ktsixitauthorJul 30.2009 — 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.
Copy linkTweet thisAlerts:
@KorJul 30.2009 — 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.
Copy linkTweet thisAlerts:
@TcobbJul 31.2009 — 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.
×

Success!

Help @ktsixit spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...