tags:

views:

59

answers:

2

I am using the jQuery RoundedCorners and it works great. Since I am doing AJAX calls I wanted to continue rounding my corners on the divs that I am appending with my AJAX callbacks.

To get rounded corners I use this syntax

$(document).ready(function(){
   $(".item").corner();
});

Since the document is already ready while I am making AJAX calls, this won't make my newly appended items rounded. I tried to make this call after I append to my html but it didnt work.

Any ideas on how to use this method so I dont have to use a second type to round corners after AJAX embeds new divs?

Thanks so much!

A: 

Add .corner() to the div you fill with the result of your Ajax request.

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html).corner();
  }
});
powtac
I am appending multiple divs inside that #results div looping... so I can't do that exactly...I dont want to round the #results div, i want to round the div that I am appending inside the #results div.
gmcalab
What, exactly, does the relevant section of the DOM look like before and after?
James A. Rosen
Basically I am using ajax to filter results... so when u click a category it uses ajax to requery and the return a JSON result. then i iterate thru the data and append div containers for each result. so i want to round the corners for each div. so it looks the same before and after just with filtered results
gmcalab
A: 

Perhaps keep track of (or find) the number of .items before the ajax call, then use :gt(index) to only affect the new items?

i.e. something like:

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    var numItems = $("#results .item").length;
    //however you load data
    $("#results .item:gt(numItems-1)").corner();
  }
});


EDIT: From your comments on @powtac's answer, it sounds like you may be completely re-loading the contents of the #results div. If that is the case, you won't need to worry about pre-existing .item divs and can use this:

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    //however you load data
    $("#results .item").corner();
  }
});
t_scho
Yes sir, that's exactly what I did. Thanks!
gmcalab