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 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    jQuery trouble loading stylesheet

    I'm trying to load a css file as needed. I'm looking for the #slider as my trigger. If it exists, then load this style sheet.

    I've tried both methods below and neither work. Am I missing something somewhere?

    Code:
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script>
    <script type="text/javascript">
                $(document).ready( function() {
              
                   if ( $("#slider").length > 0) {
                    $('<link>').appendTo('head').attr({
          rel:  "stylesheet",
          type: "text/css",
          href: "/css/controls10.css"
        });
                 
                }
             });
    </script>-->
    
      <script type="text/javascript">
                $(document).ready( function() {
              
                   if ( $("#slider")) {
    								 $("link[rel=stylesheet]").attr({href : "css/controls10.css"});
                 
                }
             });
    Also is there a way to cache the plugin call? I read .getScript doesn't cache so I tried .ajax.

    Code:
    $.ajax({
                type: 'GET',
                url: 'xxx',
                cache: true,
                success: function() {$("#slider").easySlider({
    				auto: true, 
    				continuous: true,
    				numeric: true,
    				numericId: 'controls',
    				speed: 800,
    				pause:	6000
    
    			}); },
                dataType: 'script',
                data: null
             });
    I only want to make the function call and not use a url. (Since there is no file needed to run this.)

    Any help is appreciated
    Last edited by finstah1; 02-15-2010 at 10:14 PM.

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I figured out the first part.

    Code:
     $('head').append('<link rel="stylesheet" href="css/controls10.css" type="text/css" />');


  •  

    Posting Permissions

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