Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Jquery .load() question. CSS not showing up.

    Playing around with .load() and wrote a simple script.

    User clicks on a link, and then a .php page gets called from that link.

    The php page which is loaded has a bunch of different css styles on it.

    The classes and ID's from the loaded php page is included on the parent page...

    for example if the page is index.php and I am loading test.php, all of the necessary CSS for test.php is in the <head> of index.php.


    However, when the page loads, the CSS does not get shown from the loaded page.... even tho the necessary classes are there. Any ideas?

    Code:
    <script>
    $(document).ready(function () {
    $("#test1").click(function () {
    			$('#bodyContainer').fadeOut('slow', function () {
    	$('#loader').load('test.php');
    					}); 
    			});
    			
    			});
    			</script>
    Any help would be greatly appreciated. Thanks!

  • #2
    New Coder
    Join Date
    Jun 2011
    Posts
    80
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Have you tried using the function with .live() rather than .click()?

    $("#test1").live('click', function () {

    ....

    });

    http://api.jquery.com/live/

    Just a thought - I'm not too experienced myself.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    No, I suspect live() won’t do anything here. It would help to actually see the entire code of the parent page where test.php is included.

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    No, I suspect live() won’t do anything here. It would help to actually see the entire code of the parent page where test.php is included.
    Yeah. Live didnt work. The test.php page is freaking huge and i need to get this file out later today so I think I will just use a less cool way of implementing the same functionality. thanks!

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Then provide a link to the page or post a stripped down version with the relevant parts of the code. I’m sure the solution is pretty simple.

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    The classes alone are not enough if the CSS style declarations are inside the loaded content and not inside the current page. CSS style definitions will not be applied when loaded via .load() (or any Ajax technique).

    Solution: Move all your CSS to the current page (the one you are calling .load() from).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •