views:

125

answers:

2

I have a webpage... http://beta.charmscorp.com/inspect/projects.php - this webpage is in beta and doesn't currently look super professional and is only half working, also, the server internet connection is slow so it takes a bit to load up the elements properly.

Anyways, this page calls other pages through ajax to display in a div. My problem comes from wanting to use jquery to apply css to a table on a page which dynamically loads up in a div. If that sounds confusing, go ahead and go to the link I posted above, click the down arrow in the sidebar, and chose a link... Assets for example. you will see this page load up, and anything on this page won't have jquery applied to it.

From looking at solutions, I see I can add a .live() jquery function, but this seems to apply only to events and selectors. Anything i can do?

ps. this is what I've tried to do:

$("#maintable").live(function(){
      $(this).corner();
    });

This works on the main page, as you can see, there are rounded corners for the main table. However every table has the same ID, and yet, they don't have rounded corners...

+2  A: 

"every table has the same ID"

IDs are supposed to be unique. jQuery sees the first id and quits. Change those "ids" to classes and you'll be good to go.

Stefan Kendall
Thanks for really quick reply, I appreciate it! You response makes sense, however, I still have a problem that I think has to do with the jquery not being called each time I reload the page inside of the div. Any ideas on how to do this?
+1  A: 

You have an ID problem, it seems. There should never be two elements with the same ID. That said, you need to configure your server-side code so that the markup served to the AJAX request gives these tables a class attribute. Something like class="rounded". Then you can use jQuery to apply the style like this...

$("table.rounded").corner();

Note you will have to make this call each time you "reload" the div with fresh markup, which can be done globally using the ajaxComplete function...

$("table.rounded").ajaxComplete(function() {
  $(this).corner();
});
Josh Stodola
okay, thanks for the lightening fast reply! I appreciate it. So, I changed what both of you said, and I made them classes instead of ID's. However, as you can probably guess, it still doesn't work, probably because of what you said at the end about having to make the call each time I "reload" the div. I hate to sound dumb, but how do I made the jquery call? I thought it loads at the beginning of the page loading... how do I made separate calls to the jquery?
Answer updated ;)
Josh Stodola
jQuery is in fact loaded at the start, but when you make calls to it, jQuery only affects the current DOM. When you do AJAX and bring more elements into the DOM, jQuery does not automatically apply previous rules to the new elements (because doing so would be ungodly inefficient).
Josh Stodola
oh, nice, you did it! My rounded corners look like crap in IE unfortunately (firefox is usually better at everything), but at least it all works! Thanks!Side note, the corners that are applied to the ajax content are done so very slowly, as in I have to wait about 15 seconds... very strange, but maybe it has to do with the slow internet connection. I'll have to play around with it maybe. Thanks though!
shoot, sorry, I just realized something about this fix and I am hoping you can tell me why this is...So if you go to the site http://beta.charmscorp.com/inspect/projects.php - and click on media. after it loads, you'll see that the corners aren't round, if you then roll the mouse over the sidebar, they then go round... why is this?
Sounds like the classic IE hasLayout bug. Try to define a CSS rule like `div { zoom:1; }`
Josh Stodola
hmm, I applied your css rule to the table on the main page, to see if it fixed anything.. and it didn't seem to do anything. This is what I put:<table id="maintable" background="./images/box/fillwhite.png" class="lessontable" style="zoom: 75%;">I tried different percentages of zoom, but IE still messes up. FF is good though.
Also, I feel like an idiot, because my .livequery() actually was updating the table on the newly displayed page. After temporarily removing the .ajaxComplete(), I found this out. So, I guess that explains why the ajax page is only being touched by jquery AFTER I mouse over the sidebar... the question is, how do I go about fixing this? I thought .ajaxComplete would be the answer...