Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8267105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:23:50+00:00 2026-06-08T05:23:50+00:00

I am loading LessCSS from Google Code with jQuery , and want to access

  • 0

I am loading LessCSS from Google Code with jQuery, and want to access LessCSS‘ Parser() object by using less.Parser.

I can make this load LessCSS w/ jQuery by hacking in a <link rel> tag in <head>; however that loads style.less twice. I would rather load style.less and use toCSS to insert it dynamically. Doing so seems to require calling less.Parser.

Currently the code below will not insert css; I think it’s because I am not using the right namespace for the Parser class.

How can I dynamically load LessCSS with jQuery?


Original code for question

<script type="text/javascript" id="less_hack">
    // Load LessCSS javascript
    var less_file="/style.less";
    $(function() {
        var css="";
        $.getScript("toCSS.js")
        $.getScript("http://lesscss.googlecode.com/files/less-1.3.0.min.js",function(){
          $.get(less_file,function(data){
            new(less.Parser)().parse(data,function(e,tree){
              css = tree.toCSS();
            });
          });
        });
    });
    // $('head').append('<link rel="stylesheet/less" type="text/css" href="'+less_file+'">');
</script>

I am much more fluent in Python than JavaScript; apologies in advance if I have somehow missed a basic js concept.


Modified code after Patrick’s answer

<head>
<script type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
<script type="text/javascript">
    // Load LessCSS javascript
    var less_file="http://www.mysite.local/style.less";
    $(function() {
        var css="";
        $.getScript("http://lesscss.googlecode.com/files/less-1.3.0.min.js",function(){
          $.get(less_file,function(data){
            var parser = new(less.Parser);
            parser.parse(data, function (err, tree) {
                if (err) { return console.error(err) }
                css = tree.toCSS();
                // Insert rendered css inline
                $("<style/>").html(css).appendTo("body");
            });
          });
        });
    });
</script>
</head>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:23:53+00:00Added an answer on June 8, 2026 at 5:23 am

    Update:

    I think the problem was that you were calling Parser as a function, instead of an object new(less.Parser)().

    Modify your code to this:

    var less_file="/style.less";
    $(function() {
        var css="";
        $.getScript("http://lesscss.googlecode.com/files/less-1.3.0.min.js",function(){
          $.get(less_file,function(data){
            var parser = new(less.Parser);
            parser.parse(data, function (err, t) {
                if (err) { return console.error(err) }
                css = t.toCSS();
                $("<style/>").html(css).appendTo("body");
            });            
          });
        });
    });
    

    See a working version here: http://jsfiddle.net/E6hsC/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After loading a PHP template (using jQuery's load function), this simple script won't make
trouble loading html file from plist to webView using following code in FAQDetailViewController.m: -
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file
When loading a html page using JQuery load, I also need to call another
When loading tables from SAS to Teradata, SAS loads the data (usually using the
After loading in a store of user roles [id, name] I can easily make
when loading a .dll file from lua it gives me this error: loop or
After loading updatepanel through Timer, i am unable to make any async request from
Loading a CGImage or NSImage from a file using a standard image format (jpeg,
When loading a document from iCloud, one must make a call to openWithCompletionHandler:^(BOOL success)completionHandler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.