How do I access JavaScript variable under Color portion of HTML code?












1















I would like to access the variable "theSkyColour" inside the HTML code below as shown. May I know how do I access it as shown?



The following is the code I have written:






function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>





I have viewed other answers like the one here: Javascript variable access in HTML, however, it did not work for me as I am unable to change the color of the sky in the viewing page.



I've created the following HTML pages.
1. A settings page to adjust the color of the sky saved in a localStorage as "skyColor".
2. A viewing page for the user to view the color of the sky.



The reason why I have an a-sky tag is that I am using aframe.io



Update: After attempting to use JavaScript along with localStorage Sessions:



Javascript Code:



<script>
function getSkyColor() {
var theSkyColor = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColor+";
bottomColor:"+theSkyColor+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)
</script>


HTML Code:



  <a-sky id="skyColor" src="#sky" material="shader:gradient; offset:0;"></a-sky>


Unfortunately, it still does not work, as the display I get is not what I have expected, which is a night sky under the RGB color: 41 35 71. (See attached screenshot)



Failed display of desired colors RGB 41 35 71



What I want and What I have










share|improve this question

























  • It's not possible to access javascript variable in html.

    – Raja Sekar
    Nov 19 '18 at 9:59











  • check this: w3schools.com/js/js_htmldom_css.asp

    – MrAleister
    Nov 19 '18 at 10:00






  • 2





    "It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

    – mplungjan
    Nov 19 '18 at 10:03













  • Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

    – Mohammad Zare Moghadam
    Nov 19 '18 at 10:09


















1















I would like to access the variable "theSkyColour" inside the HTML code below as shown. May I know how do I access it as shown?



The following is the code I have written:






function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>





I have viewed other answers like the one here: Javascript variable access in HTML, however, it did not work for me as I am unable to change the color of the sky in the viewing page.



I've created the following HTML pages.
1. A settings page to adjust the color of the sky saved in a localStorage as "skyColor".
2. A viewing page for the user to view the color of the sky.



The reason why I have an a-sky tag is that I am using aframe.io



Update: After attempting to use JavaScript along with localStorage Sessions:



Javascript Code:



<script>
function getSkyColor() {
var theSkyColor = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColor+";
bottomColor:"+theSkyColor+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)
</script>


HTML Code:



  <a-sky id="skyColor" src="#sky" material="shader:gradient; offset:0;"></a-sky>


Unfortunately, it still does not work, as the display I get is not what I have expected, which is a night sky under the RGB color: 41 35 71. (See attached screenshot)



Failed display of desired colors RGB 41 35 71



What I want and What I have










share|improve this question

























  • It's not possible to access javascript variable in html.

    – Raja Sekar
    Nov 19 '18 at 9:59











  • check this: w3schools.com/js/js_htmldom_css.asp

    – MrAleister
    Nov 19 '18 at 10:00






  • 2





    "It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

    – mplungjan
    Nov 19 '18 at 10:03













  • Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

    – Mohammad Zare Moghadam
    Nov 19 '18 at 10:09
















1












1








1








I would like to access the variable "theSkyColour" inside the HTML code below as shown. May I know how do I access it as shown?



The following is the code I have written:






function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>





I have viewed other answers like the one here: Javascript variable access in HTML, however, it did not work for me as I am unable to change the color of the sky in the viewing page.



I've created the following HTML pages.
1. A settings page to adjust the color of the sky saved in a localStorage as "skyColor".
2. A viewing page for the user to view the color of the sky.



The reason why I have an a-sky tag is that I am using aframe.io



Update: After attempting to use JavaScript along with localStorage Sessions:



Javascript Code:



<script>
function getSkyColor() {
var theSkyColor = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColor+";
bottomColor:"+theSkyColor+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)
</script>


HTML Code:



  <a-sky id="skyColor" src="#sky" material="shader:gradient; offset:0;"></a-sky>


Unfortunately, it still does not work, as the display I get is not what I have expected, which is a night sky under the RGB color: 41 35 71. (See attached screenshot)



Failed display of desired colors RGB 41 35 71



What I want and What I have










share|improve this question
















I would like to access the variable "theSkyColour" inside the HTML code below as shown. May I know how do I access it as shown?



The following is the code I have written:






function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>





I have viewed other answers like the one here: Javascript variable access in HTML, however, it did not work for me as I am unable to change the color of the sky in the viewing page.



I've created the following HTML pages.
1. A settings page to adjust the color of the sky saved in a localStorage as "skyColor".
2. A viewing page for the user to view the color of the sky.



The reason why I have an a-sky tag is that I am using aframe.io



Update: After attempting to use JavaScript along with localStorage Sessions:



Javascript Code:



<script>
function getSkyColor() {
var theSkyColor = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColor+";
bottomColor:"+theSkyColor+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)
</script>


HTML Code:



  <a-sky id="skyColor" src="#sky" material="shader:gradient; offset:0;"></a-sky>


Unfortunately, it still does not work, as the display I get is not what I have expected, which is a night sky under the RGB color: 41 35 71. (See attached screenshot)



Failed display of desired colors RGB 41 35 71



What I want and What I have






function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>





function getSkyColour() {
var theSkyColour = localStorage.getItem('skySet[enter image description here][1]ting');
}

<a-sky id="skyColor" src="#sky" 
material="shader:gradient; topColor: <<I want to access theSkyColor here>>; bottomColor: <<I want to access theSkyColor here>> ; offset:0;"></a-sky>






javascript html variables web-component aframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 14:51







Jim Ng

















asked Nov 19 '18 at 9:56









Jim NgJim Ng

85




85













  • It's not possible to access javascript variable in html.

    – Raja Sekar
    Nov 19 '18 at 9:59











  • check this: w3schools.com/js/js_htmldom_css.asp

    – MrAleister
    Nov 19 '18 at 10:00






  • 2





    "It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

    – mplungjan
    Nov 19 '18 at 10:03













  • Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

    – Mohammad Zare Moghadam
    Nov 19 '18 at 10:09





















  • It's not possible to access javascript variable in html.

    – Raja Sekar
    Nov 19 '18 at 9:59











  • check this: w3schools.com/js/js_htmldom_css.asp

    – MrAleister
    Nov 19 '18 at 10:00






  • 2





    "It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

    – mplungjan
    Nov 19 '18 at 10:03













  • Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

    – Mohammad Zare Moghadam
    Nov 19 '18 at 10:09



















It's not possible to access javascript variable in html.

– Raja Sekar
Nov 19 '18 at 9:59





It's not possible to access javascript variable in html.

– Raja Sekar
Nov 19 '18 at 9:59













check this: w3schools.com/js/js_htmldom_css.asp

– MrAleister
Nov 19 '18 at 10:00





check this: w3schools.com/js/js_htmldom_css.asp

– MrAleister
Nov 19 '18 at 10:00




2




2





"It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

– mplungjan
Nov 19 '18 at 10:03







"It did not work for me" how? It is not very descriptive. Please update the snippet I made for you with your attempts - Also please tell us what framework has <a-sky tags

– mplungjan
Nov 19 '18 at 10:03















Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

– Mohammad Zare Moghadam
Nov 19 '18 at 10:09







Tri this: document.getElementById('skyColor').setAttribute('material', document.getElementById('skyColor').getAttribute('style')+'; color: '+getSkyColour());

– Mohammad Zare Moghadam
Nov 19 '18 at 10:09














3 Answers
3






active

oldest

votes


















0














Unless you are using a framework like Angular or django, it is not possible to access variables in your HTML code, instead you can construct the attribute in your Javascript and add it to the element.



EX:



var myAttr = "shader:gradient; topColor:"+skyColor+"; bottomColor:"+skyColor+"; offset:0;"
$("#skyColor").attr("material",myAttr)


Update: without using jQuery:



<script>
function getSkyColour() {
var theSkyColour = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColour+"; bottomColor:"+theSkyColour+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)

</script>





share|improve this answer


























  • For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

    – Jim Ng
    Nov 19 '18 at 14:38











  • This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

    – Suhas NM
    Nov 19 '18 at 15:24











  • I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

    – Jim Ng
    Nov 19 '18 at 15:29











  • Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

    – Suhas NM
    Nov 19 '18 at 15:31











  • I will update my answer to your requirement

    – Suhas NM
    Nov 19 '18 at 15:33



















0














check out the snippets for getting and setting attributesin an a-frame component. Refer to the following documentation:



https://aframe.io/docs/0.8.0/core/entity.html#getattribute-componentname



It explains very well how to get and how to set values from component properties and sub-properties:



Get Property



enter image description here



Set Property
enter image description here






share|improve this answer
























  • Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

    – Jim Ng
    Nov 19 '18 at 14:04











  • I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

    – Sunny Sharma
    Nov 19 '18 at 14:15



















0














You can’t, but you can change the function to update the color of the sky.



document.getElementById("skyColor").material = `defaultStylesInHere topColor:${localStorage.getItem("skyColor")};`;


Update



let setSkyColor = (val) => {
localStorage.setItem('skyColor', `defaultStylesInHere topColor:${val};bottomColor:${val}`);
}
let loadSkyColor = () => {
document.getElementById('skyColor').attributes.material = localStorage.getItem('skyColor');
}


I can make full functions, but it should not be necessary

You could also use JSON or Objects to set and grab sky properties



let app = {
skyProp: {
/*
color: 'rgba(200, 200, 255, 1)',
OR
color: {
default: {
color: 'rgba(200, 200, 255, 1)',
topColor: 'green',
},
night: {
color: 'rgba(255, 255, 255, 1)',
bottomColor: 'rgba(155, 155, 155, 1)',
}
}
*/
}
}





share|improve this answer





















  • 1





    You likely want getAttribute("material") here

    – mplungjan
    Nov 19 '18 at 10:08






  • 1





    Please do not use curly quotes - are you updating on a phone?

    – mplungjan
    Nov 19 '18 at 10:09






  • 1





    You can add comments as comments, no need to edit the post for that.

    – Luca Kiebel
    Nov 19 '18 at 10:10











  • Yes, I am using a phone, it was stated at the bottom of my post

    – DarkHeart Productions
    Nov 19 '18 at 10:21






  • 2





    Oh wow, did not see that. :/

    – DarkHeart Productions
    Nov 19 '18 at 10:28











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',
autoActivateHeartbeat: false,
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%2f53372122%2fhow-do-i-access-javascript-variable-under-color-portion-of-html-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Unless you are using a framework like Angular or django, it is not possible to access variables in your HTML code, instead you can construct the attribute in your Javascript and add it to the element.



EX:



var myAttr = "shader:gradient; topColor:"+skyColor+"; bottomColor:"+skyColor+"; offset:0;"
$("#skyColor").attr("material",myAttr)


Update: without using jQuery:



<script>
function getSkyColour() {
var theSkyColour = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColour+"; bottomColor:"+theSkyColour+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)

</script>





share|improve this answer


























  • For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

    – Jim Ng
    Nov 19 '18 at 14:38











  • This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

    – Suhas NM
    Nov 19 '18 at 15:24











  • I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

    – Jim Ng
    Nov 19 '18 at 15:29











  • Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

    – Suhas NM
    Nov 19 '18 at 15:31











  • I will update my answer to your requirement

    – Suhas NM
    Nov 19 '18 at 15:33
















0














Unless you are using a framework like Angular or django, it is not possible to access variables in your HTML code, instead you can construct the attribute in your Javascript and add it to the element.



EX:



var myAttr = "shader:gradient; topColor:"+skyColor+"; bottomColor:"+skyColor+"; offset:0;"
$("#skyColor").attr("material",myAttr)


Update: without using jQuery:



<script>
function getSkyColour() {
var theSkyColour = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColour+"; bottomColor:"+theSkyColour+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)

</script>





share|improve this answer


























  • For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

    – Jim Ng
    Nov 19 '18 at 14:38











  • This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

    – Suhas NM
    Nov 19 '18 at 15:24











  • I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

    – Jim Ng
    Nov 19 '18 at 15:29











  • Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

    – Suhas NM
    Nov 19 '18 at 15:31











  • I will update my answer to your requirement

    – Suhas NM
    Nov 19 '18 at 15:33














0












0








0







Unless you are using a framework like Angular or django, it is not possible to access variables in your HTML code, instead you can construct the attribute in your Javascript and add it to the element.



EX:



var myAttr = "shader:gradient; topColor:"+skyColor+"; bottomColor:"+skyColor+"; offset:0;"
$("#skyColor").attr("material",myAttr)


Update: without using jQuery:



<script>
function getSkyColour() {
var theSkyColour = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColour+"; bottomColor:"+theSkyColour+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)

</script>





share|improve this answer















Unless you are using a framework like Angular or django, it is not possible to access variables in your HTML code, instead you can construct the attribute in your Javascript and add it to the element.



EX:



var myAttr = "shader:gradient; topColor:"+skyColor+"; bottomColor:"+skyColor+"; offset:0;"
$("#skyColor").attr("material",myAttr)


Update: without using jQuery:



<script>
function getSkyColour() {
var theSkyColour = localStorage.getItem('skySetting');
}
getSkyColour()

var myAttr = "shader:gradient; topColor:"+theSkyColour+"; bottomColor:"+theSkyColour+"; offset:0;"
document.getElementById(‘skyColor’).setAttribute(“material”,myAttr)

</script>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 15:43

























answered Nov 19 '18 at 10:09









Suhas NMSuhas NM

1175




1175













  • For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

    – Jim Ng
    Nov 19 '18 at 14:38











  • This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

    – Suhas NM
    Nov 19 '18 at 15:24











  • I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

    – Jim Ng
    Nov 19 '18 at 15:29











  • Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

    – Suhas NM
    Nov 19 '18 at 15:31











  • I will update my answer to your requirement

    – Suhas NM
    Nov 19 '18 at 15:33



















  • For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

    – Jim Ng
    Nov 19 '18 at 14:38











  • This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

    – Suhas NM
    Nov 19 '18 at 15:24











  • I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

    – Jim Ng
    Nov 19 '18 at 15:29











  • Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

    – Suhas NM
    Nov 19 '18 at 15:31











  • I will update my answer to your requirement

    – Suhas NM
    Nov 19 '18 at 15:33

















For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

– Jim Ng
Nov 19 '18 at 14:38





For the second line "$("#skyColor").attr("material",myAttr)" , may I know where should I place this line of code? Is this a PHP code? How do I use it?

– Jim Ng
Nov 19 '18 at 14:38













This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

– Suhas NM
Nov 19 '18 at 15:24





This is a jQuery code, you need to have jQuery library in your application to use it. If you do not have jQuey library, I will suggest an alternative to it in pure JavaScript

– Suhas NM
Nov 19 '18 at 15:24













I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

– Jim Ng
Nov 19 '18 at 15:29





I would like to use pure Javascript as well. However, like I mentioned in the original post, there is a problem of being unable to call it inside the HTML code with Javascript. So I'm confused. What should I do here if I would like to use pure Javascript?

– Jim Ng
Nov 19 '18 at 15:29













Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

– Suhas NM
Nov 19 '18 at 15:31





Basically, any JavaScript you use goes inside “<script> your JavaScript </script>”

– Suhas NM
Nov 19 '18 at 15:31













I will update my answer to your requirement

– Suhas NM
Nov 19 '18 at 15:33





I will update my answer to your requirement

– Suhas NM
Nov 19 '18 at 15:33













0














check out the snippets for getting and setting attributesin an a-frame component. Refer to the following documentation:



https://aframe.io/docs/0.8.0/core/entity.html#getattribute-componentname



It explains very well how to get and how to set values from component properties and sub-properties:



Get Property



enter image description here



Set Property
enter image description here






share|improve this answer
























  • Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

    – Jim Ng
    Nov 19 '18 at 14:04











  • I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

    – Sunny Sharma
    Nov 19 '18 at 14:15
















0














check out the snippets for getting and setting attributesin an a-frame component. Refer to the following documentation:



https://aframe.io/docs/0.8.0/core/entity.html#getattribute-componentname



It explains very well how to get and how to set values from component properties and sub-properties:



Get Property



enter image description here



Set Property
enter image description here






share|improve this answer
























  • Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

    – Jim Ng
    Nov 19 '18 at 14:04











  • I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

    – Sunny Sharma
    Nov 19 '18 at 14:15














0












0








0







check out the snippets for getting and setting attributesin an a-frame component. Refer to the following documentation:



https://aframe.io/docs/0.8.0/core/entity.html#getattribute-componentname



It explains very well how to get and how to set values from component properties and sub-properties:



Get Property



enter image description here



Set Property
enter image description here






share|improve this answer













check out the snippets for getting and setting attributesin an a-frame component. Refer to the following documentation:



https://aframe.io/docs/0.8.0/core/entity.html#getattribute-componentname



It explains very well how to get and how to set values from component properties and sub-properties:



Get Property



enter image description here



Set Property
enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 11:14









Sunny SharmaSunny Sharma

2,67042050




2,67042050













  • Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

    – Jim Ng
    Nov 19 '18 at 14:04











  • I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

    – Sunny Sharma
    Nov 19 '18 at 14:15



















  • Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

    – Jim Ng
    Nov 19 '18 at 14:04











  • I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

    – Sunny Sharma
    Nov 19 '18 at 14:15

















Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

– Jim Ng
Nov 19 '18 at 14:04





Does this apply in my scenario, considering that I am accessing a local session? I am using some aframe components, however, I am not sure if it works since I am changing a local session on another HTML page. Could you advise if there is an alternative for using local sessions storage?

– Jim Ng
Nov 19 '18 at 14:04













I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

– Sunny Sharma
Nov 19 '18 at 14:15





I don't think templating is available for aframe at component sub-properties level, as they're one string. I think you can modify the values right after initialization of the frame. Not sure how it is done yet!

– Sunny Sharma
Nov 19 '18 at 14:15











0














You can’t, but you can change the function to update the color of the sky.



document.getElementById("skyColor").material = `defaultStylesInHere topColor:${localStorage.getItem("skyColor")};`;


Update



let setSkyColor = (val) => {
localStorage.setItem('skyColor', `defaultStylesInHere topColor:${val};bottomColor:${val}`);
}
let loadSkyColor = () => {
document.getElementById('skyColor').attributes.material = localStorage.getItem('skyColor');
}


I can make full functions, but it should not be necessary

You could also use JSON or Objects to set and grab sky properties



let app = {
skyProp: {
/*
color: 'rgba(200, 200, 255, 1)',
OR
color: {
default: {
color: 'rgba(200, 200, 255, 1)',
topColor: 'green',
},
night: {
color: 'rgba(255, 255, 255, 1)',
bottomColor: 'rgba(155, 155, 155, 1)',
}
}
*/
}
}





share|improve this answer





















  • 1





    You likely want getAttribute("material") here

    – mplungjan
    Nov 19 '18 at 10:08






  • 1





    Please do not use curly quotes - are you updating on a phone?

    – mplungjan
    Nov 19 '18 at 10:09






  • 1





    You can add comments as comments, no need to edit the post for that.

    – Luca Kiebel
    Nov 19 '18 at 10:10











  • Yes, I am using a phone, it was stated at the bottom of my post

    – DarkHeart Productions
    Nov 19 '18 at 10:21






  • 2





    Oh wow, did not see that. :/

    – DarkHeart Productions
    Nov 19 '18 at 10:28
















0














You can’t, but you can change the function to update the color of the sky.



document.getElementById("skyColor").material = `defaultStylesInHere topColor:${localStorage.getItem("skyColor")};`;


Update



let setSkyColor = (val) => {
localStorage.setItem('skyColor', `defaultStylesInHere topColor:${val};bottomColor:${val}`);
}
let loadSkyColor = () => {
document.getElementById('skyColor').attributes.material = localStorage.getItem('skyColor');
}


I can make full functions, but it should not be necessary

You could also use JSON or Objects to set and grab sky properties



let app = {
skyProp: {
/*
color: 'rgba(200, 200, 255, 1)',
OR
color: {
default: {
color: 'rgba(200, 200, 255, 1)',
topColor: 'green',
},
night: {
color: 'rgba(255, 255, 255, 1)',
bottomColor: 'rgba(155, 155, 155, 1)',
}
}
*/
}
}





share|improve this answer





















  • 1





    You likely want getAttribute("material") here

    – mplungjan
    Nov 19 '18 at 10:08






  • 1





    Please do not use curly quotes - are you updating on a phone?

    – mplungjan
    Nov 19 '18 at 10:09






  • 1





    You can add comments as comments, no need to edit the post for that.

    – Luca Kiebel
    Nov 19 '18 at 10:10











  • Yes, I am using a phone, it was stated at the bottom of my post

    – DarkHeart Productions
    Nov 19 '18 at 10:21






  • 2





    Oh wow, did not see that. :/

    – DarkHeart Productions
    Nov 19 '18 at 10:28














0












0








0







You can’t, but you can change the function to update the color of the sky.



document.getElementById("skyColor").material = `defaultStylesInHere topColor:${localStorage.getItem("skyColor")};`;


Update



let setSkyColor = (val) => {
localStorage.setItem('skyColor', `defaultStylesInHere topColor:${val};bottomColor:${val}`);
}
let loadSkyColor = () => {
document.getElementById('skyColor').attributes.material = localStorage.getItem('skyColor');
}


I can make full functions, but it should not be necessary

You could also use JSON or Objects to set and grab sky properties



let app = {
skyProp: {
/*
color: 'rgba(200, 200, 255, 1)',
OR
color: {
default: {
color: 'rgba(200, 200, 255, 1)',
topColor: 'green',
},
night: {
color: 'rgba(255, 255, 255, 1)',
bottomColor: 'rgba(155, 155, 155, 1)',
}
}
*/
}
}





share|improve this answer















You can’t, but you can change the function to update the color of the sky.



document.getElementById("skyColor").material = `defaultStylesInHere topColor:${localStorage.getItem("skyColor")};`;


Update



let setSkyColor = (val) => {
localStorage.setItem('skyColor', `defaultStylesInHere topColor:${val};bottomColor:${val}`);
}
let loadSkyColor = () => {
document.getElementById('skyColor').attributes.material = localStorage.getItem('skyColor');
}


I can make full functions, but it should not be necessary

You could also use JSON or Objects to set and grab sky properties



let app = {
skyProp: {
/*
color: 'rgba(200, 200, 255, 1)',
OR
color: {
default: {
color: 'rgba(200, 200, 255, 1)',
topColor: 'green',
},
night: {
color: 'rgba(255, 255, 255, 1)',
bottomColor: 'rgba(155, 155, 155, 1)',
}
}
*/
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 1:47

























answered Nov 19 '18 at 10:04









DarkHeart ProductionsDarkHeart Productions

565




565








  • 1





    You likely want getAttribute("material") here

    – mplungjan
    Nov 19 '18 at 10:08






  • 1





    Please do not use curly quotes - are you updating on a phone?

    – mplungjan
    Nov 19 '18 at 10:09






  • 1





    You can add comments as comments, no need to edit the post for that.

    – Luca Kiebel
    Nov 19 '18 at 10:10











  • Yes, I am using a phone, it was stated at the bottom of my post

    – DarkHeart Productions
    Nov 19 '18 at 10:21






  • 2





    Oh wow, did not see that. :/

    – DarkHeart Productions
    Nov 19 '18 at 10:28














  • 1





    You likely want getAttribute("material") here

    – mplungjan
    Nov 19 '18 at 10:08






  • 1





    Please do not use curly quotes - are you updating on a phone?

    – mplungjan
    Nov 19 '18 at 10:09






  • 1





    You can add comments as comments, no need to edit the post for that.

    – Luca Kiebel
    Nov 19 '18 at 10:10











  • Yes, I am using a phone, it was stated at the bottom of my post

    – DarkHeart Productions
    Nov 19 '18 at 10:21






  • 2





    Oh wow, did not see that. :/

    – DarkHeart Productions
    Nov 19 '18 at 10:28








1




1





You likely want getAttribute("material") here

– mplungjan
Nov 19 '18 at 10:08





You likely want getAttribute("material") here

– mplungjan
Nov 19 '18 at 10:08




1




1





Please do not use curly quotes - are you updating on a phone?

– mplungjan
Nov 19 '18 at 10:09





Please do not use curly quotes - are you updating on a phone?

– mplungjan
Nov 19 '18 at 10:09




1




1





You can add comments as comments, no need to edit the post for that.

– Luca Kiebel
Nov 19 '18 at 10:10





You can add comments as comments, no need to edit the post for that.

– Luca Kiebel
Nov 19 '18 at 10:10













Yes, I am using a phone, it was stated at the bottom of my post

– DarkHeart Productions
Nov 19 '18 at 10:21





Yes, I am using a phone, it was stated at the bottom of my post

– DarkHeart Productions
Nov 19 '18 at 10:21




2




2





Oh wow, did not see that. :/

– DarkHeart Productions
Nov 19 '18 at 10:28





Oh wow, did not see that. :/

– DarkHeart Productions
Nov 19 '18 at 10:28


















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372122%2fhow-do-i-access-javascript-variable-under-color-portion-of-html-code%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

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?