using .live and (document).ready together

hi,

i'm fairly new to jquery so please bear with me if this is a stupid question :)

i have a simple jquery which gives rounded corners to a few divs :

<script type="text/javascript">
 $(document).ready(function(){
    $('div.admin_head1').corner('right');
    $('div.admin_head2').corner('right');
    $('div.con_list_item').corner('right');
});
</script>

this works fine for the first 2 divs (admin_head1 and admin_head2).

my problem is that there is a javascript "onload" in the body tag which calls another jquery which uses ajax and loads in a URL a inserts tthis data into a placeholder div... in this loaded html there are a number of divs with the class 'con_list_item'. these newly added divs i want to also have rounded corners as in the final line of the original jquery.

i see that the problem is that because these divs don't exist when the page is first ready then the jquery can't apply it to them... i've read that the solution is to use the .live event to apply jquery calls to objects that will exist in the future...

i've looked around and can't find any examples which do exactly what i want... all references to the 'live' event are usually based around binding to an 'onclick' event or to a link...

how can i get my jquery to work where it applies on document ready AND on any future occurrences of the divs in question?

thank

dog

dog_starAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
>>these newly added divs i want to also have rounded corners as in the final line of the original jquery.
OK, so right after you have inserted into the page, execute:
$('div.con_list_item').corner('right');

again.
0
StealthyDevCommented:
Document.ready is nothing but a function that is called after all the components of the page is fully loaded and ready.

If you have any onload function of a body tag, just remove it and bring it to the document.ready function.

May be like the code attached:

Best regards.


<script type="text/javascript">
 $(document).ready(function(){
    MyOnLoadFunction();
    $('div.admin_head1').corner('right');
    $('div.admin_head2').corner('right');
    $('div.con_list_item').corner('right');
});
</script>

Open in new window

0
dog_starAuthor Commented:
@hielo : this is my problem... as the divs don't as such when the page is loaded then it can't apply the jquery to these divs.. this is why i think using the .live event would solve my problem, i'm just unsure of the syntax to use...

@senthurpandian :  yes, thats a good idea, and i've changed my code to something similar to what you gave in your example, but this doesn't solve the problem... the divs which are displayed are dynamically created by running through a recordset so the divs themselves don't exist until after the ready functions have been called... so, i think i need to use the .live event to apply the '$('div.con_list_item').corner('right');' line to every future occurrence of the 'con_list_item' class...

does this make sense?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

hieloCommented:
you missed my point. Yes, I know at page load the divs do NOT exist yet, but you said you are making an ajax call. You should execute a callback function upon sucess and within that call back function insert the ajax result into your page AND then execute the code you need  to execute:
$.ajax({
  "url":"..."
  ,"success":function(text){
    $('#targetDiv').append(text);
    $('div.con_list_item').corner('right');
  }
});
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dog_starAuthor Commented:
@hielo : yes, you're right, that worked great...

in the end my script looked like this :

function loadContent(varType){
var loadUrl = "content_list.asp?type="+varType;

$("#content_div").html(ajax_load).load(loadUrl, function() {
  $('div.con_list_item').corner('right');
});
}

or like this...

$.ajax({
  url: "content_list.asp?type="+varType,
  error: function() {
             alert('an error occurred!');
  },
  success: function(text) {
    $('#content_div').append(text);
      $('div.con_list_item').corner('right');
            },
});

thanks for the help :)
0
dog_starAuthor Commented:
@hielo : yes, you're right, that worked great...

in the end my script looked like this :

function loadContent(varType){
$.ajaxSetup ({
      cache: false
      });

var loadUrl = "content_list.asp?type="+varType;
$("#content_div").html(ajax_load).load(loadUrl, function() {
  $('div.con_list_item').corner('right');
});
}


$.ajax({
  url: "content_list.asp?type="+varType,
  error: function() {
             alert('an error occurred!');
  },
  success: function(text) {
    $('#content_div').append(text);
      $('div.con_list_item').corner('right');
            },
});
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.