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.
jquery less
add a comment |
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.
jquery less
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
add a comment |
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.
jquery less
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
jquery less
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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