javascript - Accessing DOM object after AJAX call? -


i have typical ajax call appends html current page. want able access newly inserted html typical jquery selectors.

here's i'd like able do...

$.ajax({    url: url,    success: function(data) {       $('body').append(data);    } });  $('#new_div').show(); 

#new_div html element data retrieved. don't want attach events new elements (like click), using .load() or .on() doesn't work here (as far know).

i tried setting $.ajax() call variable: var new_div = $.ajax(...) didn't me anywhere.

if manipulate new content after (or before) inserting dom, can put in ajax success callback too:

$.ajax({    url: url,    success: function(data) {       $('body').append(data);       $('#new_div').show();    } }); 

on other hand, if want bind handlers content added page via ajax, jquery this:

$(document).on('click', '#new_div', function(){   alert("this function bound #new_div's click events, if added dom via ajax later!") }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -