Reload page with new LESS file











up vote
0
down vote

favorite












I have a page with the following select box on it:



    <form>
<select id="themelist">
<option value="style.less">Style 1</option>
<option value="style-2.less">Style 2</option>
</select>
</form>


and this in the head:



<link rel="stylesheet/less" type="text/css" href="style.less" id="lesslink">
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js"></script>


I also have the following in my script.js:



    $("#themelist").change(function() {
var newTheme = $("#themelist option:selected").val()
$("#lesslink").attr({href : newTheme});
});


When I choose Style 2 from the dropdown, I get no errors, but it doesn't switch the style of the page. I know I'm getting into the function, and that newTheme is the right value, via alerts.



What am I missing here?



Thanks,



EDIT: After further review, it seems that going from style to style-2 enacts a few small CSS changes that are consistent, but random, and going from style-2 to style does nothing. Which now totally confuses me. This is also with using less.refresh(). Also, no errors are thrown in the console.










share|improve this question




















  • 1




    Duplicate of Load less.js rules dynamically
    – seven-phases-max
    Nov 20 at 13:32












  • Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
    – Reverend Bubbles
    Nov 20 at 14:49















up vote
0
down vote

favorite












I have a page with the following select box on it:



    <form>
<select id="themelist">
<option value="style.less">Style 1</option>
<option value="style-2.less">Style 2</option>
</select>
</form>


and this in the head:



<link rel="stylesheet/less" type="text/css" href="style.less" id="lesslink">
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js"></script>


I also have the following in my script.js:



    $("#themelist").change(function() {
var newTheme = $("#themelist option:selected").val()
$("#lesslink").attr({href : newTheme});
});


When I choose Style 2 from the dropdown, I get no errors, but it doesn't switch the style of the page. I know I'm getting into the function, and that newTheme is the right value, via alerts.



What am I missing here?



Thanks,



EDIT: After further review, it seems that going from style to style-2 enacts a few small CSS changes that are consistent, but random, and going from style-2 to style does nothing. Which now totally confuses me. This is also with using less.refresh(). Also, no errors are thrown in the console.










share|improve this question




















  • 1




    Duplicate of Load less.js rules dynamically
    – seven-phases-max
    Nov 20 at 13:32












  • Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
    – Reverend Bubbles
    Nov 20 at 14:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a page with the following select box on it:



    <form>
<select id="themelist">
<option value="style.less">Style 1</option>
<option value="style-2.less">Style 2</option>
</select>
</form>


and this in the head:



<link rel="stylesheet/less" type="text/css" href="style.less" id="lesslink">
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js"></script>


I also have the following in my script.js:



    $("#themelist").change(function() {
var newTheme = $("#themelist option:selected").val()
$("#lesslink").attr({href : newTheme});
});


When I choose Style 2 from the dropdown, I get no errors, but it doesn't switch the style of the page. I know I'm getting into the function, and that newTheme is the right value, via alerts.



What am I missing here?



Thanks,



EDIT: After further review, it seems that going from style to style-2 enacts a few small CSS changes that are consistent, but random, and going from style-2 to style does nothing. Which now totally confuses me. This is also with using less.refresh(). Also, no errors are thrown in the console.










share|improve this question















I have a page with the following select box on it:



    <form>
<select id="themelist">
<option value="style.less">Style 1</option>
<option value="style-2.less">Style 2</option>
</select>
</form>


and this in the head:



<link rel="stylesheet/less" type="text/css" href="style.less" id="lesslink">
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js"></script>


I also have the following in my script.js:



    $("#themelist").change(function() {
var newTheme = $("#themelist option:selected").val()
$("#lesslink").attr({href : newTheme});
});


When I choose Style 2 from the dropdown, I get no errors, but it doesn't switch the style of the page. I know I'm getting into the function, and that newTheme is the right value, via alerts.



What am I missing here?



Thanks,



EDIT: After further review, it seems that going from style to style-2 enacts a few small CSS changes that are consistent, but random, and going from style-2 to style does nothing. Which now totally confuses me. This is also with using less.refresh(). Also, no errors are thrown in the console.







jquery less






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 15:18

























asked Nov 19 at 21:54









Reverend Bubbles

5694818




5694818








  • 1




    Duplicate of Load less.js rules dynamically
    – seven-phases-max
    Nov 20 at 13:32












  • Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
    – Reverend Bubbles
    Nov 20 at 14:49














  • 1




    Duplicate of Load less.js rules dynamically
    – seven-phases-max
    Nov 20 at 13:32












  • Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
    – Reverend Bubbles
    Nov 20 at 14:49








1




1




Duplicate of Load less.js rules dynamically
– seven-phases-max
Nov 20 at 13:32






Duplicate of Load less.js rules dynamically
– seven-phases-max
Nov 20 at 13:32














Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
– Reverend Bubbles
Nov 20 at 14:49




Not really. That question deals with how to refresh LESS when I edit the code. This question is about how to load in a brand new LESS file based on a dropdown selection. I've also tried refresh() and refreshStyles() already and neither does the trick.
– Reverend Bubbles
Nov 20 at 14:49












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I found the answer in another question on SO, but I finally searched a different way and found it.



jQuery and LESS, stylesheet update only works once



had the answer, which was the following:




This is due to the way LESS seems to work. It parses the less file,
and then adds a style attribute to the DOM. In practice, these seem to
follow the format of the following



<style type='text/css' id='less:<<NAME OF YOUR LESS FILE>>'>
/*your parsed content*/
</style>


The reason it's not loading properly is because LESS is parsing the
content, finding the existing style block, and not adding it.
Subsequent style blocks are being added at the end of head so I was
getting the 'last in' version of the style.




Once I changed the function to include the following:



$('style[id^="less:"]').remove();


before I reset the href, it worked perfectly!



To be clear, the question was different, but the answer to that question also happened to be the answer to this question in that LESS was adding its own bit of code to the end of the head that was screwing with me.






share|improve this answer























  • BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
    – Reverend Bubbles
    Nov 27 at 15:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383181%2freload-page-with-new-less-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













I found the answer in another question on SO, but I finally searched a different way and found it.



jQuery and LESS, stylesheet update only works once



had the answer, which was the following:




This is due to the way LESS seems to work. It parses the less file,
and then adds a style attribute to the DOM. In practice, these seem to
follow the format of the following



<style type='text/css' id='less:<<NAME OF YOUR LESS FILE>>'>
/*your parsed content*/
</style>


The reason it's not loading properly is because LESS is parsing the
content, finding the existing style block, and not adding it.
Subsequent style blocks are being added at the end of head so I was
getting the 'last in' version of the style.




Once I changed the function to include the following:



$('style[id^="less:"]').remove();


before I reset the href, it worked perfectly!



To be clear, the question was different, but the answer to that question also happened to be the answer to this question in that LESS was adding its own bit of code to the end of the head that was screwing with me.






share|improve this answer























  • BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
    – Reverend Bubbles
    Nov 27 at 15:05















up vote
0
down vote













I found the answer in another question on SO, but I finally searched a different way and found it.



jQuery and LESS, stylesheet update only works once



had the answer, which was the following:




This is due to the way LESS seems to work. It parses the less file,
and then adds a style attribute to the DOM. In practice, these seem to
follow the format of the following



<style type='text/css' id='less:<<NAME OF YOUR LESS FILE>>'>
/*your parsed content*/
</style>


The reason it's not loading properly is because LESS is parsing the
content, finding the existing style block, and not adding it.
Subsequent style blocks are being added at the end of head so I was
getting the 'last in' version of the style.




Once I changed the function to include the following:



$('style[id^="less:"]').remove();


before I reset the href, it worked perfectly!



To be clear, the question was different, but the answer to that question also happened to be the answer to this question in that LESS was adding its own bit of code to the end of the head that was screwing with me.






share|improve this answer























  • BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
    – Reverend Bubbles
    Nov 27 at 15:05













up vote
0
down vote










up vote
0
down vote









I found the answer in another question on SO, but I finally searched a different way and found it.



jQuery and LESS, stylesheet update only works once



had the answer, which was the following:




This is due to the way LESS seems to work. It parses the less file,
and then adds a style attribute to the DOM. In practice, these seem to
follow the format of the following



<style type='text/css' id='less:<<NAME OF YOUR LESS FILE>>'>
/*your parsed content*/
</style>


The reason it's not loading properly is because LESS is parsing the
content, finding the existing style block, and not adding it.
Subsequent style blocks are being added at the end of head so I was
getting the 'last in' version of the style.




Once I changed the function to include the following:



$('style[id^="less:"]').remove();


before I reset the href, it worked perfectly!



To be clear, the question was different, but the answer to that question also happened to be the answer to this question in that LESS was adding its own bit of code to the end of the head that was screwing with me.






share|improve this answer














I found the answer in another question on SO, but I finally searched a different way and found it.



jQuery and LESS, stylesheet update only works once



had the answer, which was the following:




This is due to the way LESS seems to work. It parses the less file,
and then adds a style attribute to the DOM. In practice, these seem to
follow the format of the following



<style type='text/css' id='less:<<NAME OF YOUR LESS FILE>>'>
/*your parsed content*/
</style>


The reason it's not loading properly is because LESS is parsing the
content, finding the existing style block, and not adding it.
Subsequent style blocks are being added at the end of head so I was
getting the 'last in' version of the style.




Once I changed the function to include the following:



$('style[id^="less:"]').remove();


before I reset the href, it worked perfectly!



To be clear, the question was different, but the answer to that question also happened to be the answer to this question in that LESS was adding its own bit of code to the end of the head that was screwing with me.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 9:03









Liam

15.9k1675125




15.9k1675125










answered Nov 20 at 16:34









Reverend Bubbles

5694818




5694818












  • BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
    – Reverend Bubbles
    Nov 27 at 15:05


















  • BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
    – Reverend Bubbles
    Nov 27 at 15:05
















BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
– Reverend Bubbles
Nov 27 at 15:05




BAH!! This was working, and now, this morning, it suddenly doesn't remove the inserted style block anymore. I'm back to square one. :(
– Reverend Bubbles
Nov 27 at 15:05


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383181%2freload-page-with-new-less-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen