How to change the style element html?
My need to after load page paint over text tag <a> in
, but I've can't this do because of this style
doesn't change the colour. I've don't know how to remove this style. This is what I've tried.
var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>Where am I doing it wrong?
Thanks.
javascript jquery
add a comment |
My need to after load page paint over text tag <a> in
, but I've can't this do because of this style
doesn't change the colour. I've don't know how to remove this style. This is what I've tried.
var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>Where am I doing it wrong?
Thanks.
javascript jquery
Don't add!importantunless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?
– Mark Baijens
Dec 28 '18 at 7:47
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
It was more an answer to the comment that is now deleted which recommended to use the!importanttag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.
– Mark Baijens
Dec 28 '18 at 8:00
add a comment |
My need to after load page paint over text tag <a> in
, but I've can't this do because of this style
doesn't change the colour. I've don't know how to remove this style. This is what I've tried.
var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>Where am I doing it wrong?
Thanks.
javascript jquery
My need to after load page paint over text tag <a> in
, but I've can't this do because of this style
doesn't change the colour. I've don't know how to remove this style. This is what I've tried.
var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>Where am I doing it wrong?
Thanks.
var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>var ParsLocat = window.location.href.replace(window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1), '').split('&');
var ParsRazd = ParsLocat[0].split('=');
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
var navAS = navA[i].children[0].search.split('&')
var navRaz = navAS[0].split('=');
if (ParsRazd[1] == navRaz[1]) {
navA[i].style.cssText = "color:white;";
break;
}
}.navbar-nav > li > a {
color: #9d9d9d;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>javascript jquery
javascript jquery
edited Dec 28 '18 at 7:50
Mark Baijens
6,766103353
6,766103353
asked Dec 28 '18 at 7:31
Dima AndrianovDima Andrianov
116
116
Don't add!importantunless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?
– Mark Baijens
Dec 28 '18 at 7:47
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
It was more an answer to the comment that is now deleted which recommended to use the!importanttag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.
– Mark Baijens
Dec 28 '18 at 8:00
add a comment |
Don't add!importantunless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?
– Mark Baijens
Dec 28 '18 at 7:47
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
It was more an answer to the comment that is now deleted which recommended to use the!importanttag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.
– Mark Baijens
Dec 28 '18 at 8:00
Don't add
!important unless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?– Mark Baijens
Dec 28 '18 at 7:47
Don't add
!important unless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?– Mark Baijens
Dec 28 '18 at 7:47
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
It was more an answer to the comment that is now deleted which recommended to use the
!important tag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.– Mark Baijens
Dec 28 '18 at 8:00
It was more an answer to the comment that is now deleted which recommended to use the
!important tag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.– Mark Baijens
Dec 28 '18 at 8:00
add a comment |
5 Answers
5
active
oldest
votes
Since the color of your anchor (a) is set to #9d9d9d, you will need to change the color of your a to white, not your li.
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>add a comment |
change
navA[i].style.cssText = "color:white;";
to
navA[i].children[0].style.color = "white";
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on thelielement instead of theaelement. I recommend testing your solution before posting it.
– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurernavA = nav.getElementsByTagName('li');stores a list oflielements. The OP wants to change theaelement. So no it will not work. Just change the line in the snippet and you will see it won't work.
– Mark Baijens
Dec 28 '18 at 8:02
|
show 1 more comment
.navbar-nav > li {
color: #9d9d9d;
}
add a comment |
it should be
navA[i].children[0].style.cssText = "color:white;";
add a comment |
Try to set the style like this:
navA[i].setAttribute('style', 'color: white;');
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
add a comment |
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
});
}
});
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%2f53955123%2fhow-to-change-the-style-element-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since the color of your anchor (a) is set to #9d9d9d, you will need to change the color of your a to white, not your li.
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>add a comment |
Since the color of your anchor (a) is set to #9d9d9d, you will need to change the color of your a to white, not your li.
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>add a comment |
Since the color of your anchor (a) is set to #9d9d9d, you will need to change the color of your a to white, not your li.
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>Since the color of your anchor (a) is set to #9d9d9d, you will need to change the color of your a to white, not your li.
var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>var nav = document.getElementById('nav');
navA = nav.getElementsByTagName('li');
for (var i = 0; i < navA.length; i++) {
navA[i].children[ 0 ].style.color = "white";
break;
}.navbar-nav > li > a {
color: #9d9d9d;
}
body {
background-color: #000000;
}<ul class="nav navbar-nav" id="nav">
<li ><a >Архивная отчетность</a></li>
<li ><a >Мониторинг</a></li>
</ul>answered Dec 28 '18 at 7:53
Thum Choon TatThum Choon Tat
2,04311116
2,04311116
add a comment |
add a comment |
change
navA[i].style.cssText = "color:white;";
to
navA[i].children[0].style.color = "white";
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on thelielement instead of theaelement. I recommend testing your solution before posting it.
– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurernavA = nav.getElementsByTagName('li');stores a list oflielements. The OP wants to change theaelement. So no it will not work. Just change the line in the snippet and you will see it won't work.
– Mark Baijens
Dec 28 '18 at 8:02
|
show 1 more comment
change
navA[i].style.cssText = "color:white;";
to
navA[i].children[0].style.color = "white";
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on thelielement instead of theaelement. I recommend testing your solution before posting it.
– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurernavA = nav.getElementsByTagName('li');stores a list oflielements. The OP wants to change theaelement. So no it will not work. Just change the line in the snippet and you will see it won't work.
– Mark Baijens
Dec 28 '18 at 8:02
|
show 1 more comment
change
navA[i].style.cssText = "color:white;";
to
navA[i].children[0].style.color = "white";
change
navA[i].style.cssText = "color:white;";
to
navA[i].children[0].style.color = "white";
edited Dec 28 '18 at 8:07
answered Dec 28 '18 at 7:52
ecstaticecstatic
1248
1248
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on thelielement instead of theaelement. I recommend testing your solution before posting it.
– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurernavA = nav.getElementsByTagName('li');stores a list oflielements. The OP wants to change theaelement. So no it will not work. Just change the line in the snippet and you will see it won't work.
– Mark Baijens
Dec 28 '18 at 8:02
|
show 1 more comment
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on thelielement instead of theaelement. I recommend testing your solution before posting it.
– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurernavA = nav.getElementsByTagName('li');stores a list oflielements. The OP wants to change theaelement. So no it will not work. Just change the line in the snippet and you will see it won't work.
– Mark Baijens
Dec 28 '18 at 8:02
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
why downvoted ?
– ecstatic
Dec 28 '18 at 7:54
Because it does not work. Still changes the color on the
li element instead of the a element. I recommend testing your solution before posting it.– Mark Baijens
Dec 28 '18 at 7:56
Because it does not work. Still changes the color on the
li element instead of the a element. I recommend testing your solution before posting it.– Mark Baijens
Dec 28 '18 at 7:56
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
Upvoted again :s It would work if it is on the right place for sure
– Sandro Schaurer
Dec 28 '18 at 7:58
1
1
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
thanks @MarkBaijens, will pay attention next time.
– ecstatic
Dec 28 '18 at 8:00
@SandroSchaurer
navA = nav.getElementsByTagName('li'); stores a list of li elements. The OP wants to change the a element. So no it will not work. Just change the line in the snippet and you will see it won't work.– Mark Baijens
Dec 28 '18 at 8:02
@SandroSchaurer
navA = nav.getElementsByTagName('li'); stores a list of li elements. The OP wants to change the a element. So no it will not work. Just change the line in the snippet and you will see it won't work.– Mark Baijens
Dec 28 '18 at 8:02
|
show 1 more comment
.navbar-nav > li {
color: #9d9d9d;
}
add a comment |
.navbar-nav > li {
color: #9d9d9d;
}
add a comment |
.navbar-nav > li {
color: #9d9d9d;
}
.navbar-nav > li {
color: #9d9d9d;
}
answered Dec 28 '18 at 7:44
HoànggHoàngg
552
552
add a comment |
add a comment |
it should be
navA[i].children[0].style.cssText = "color:white;";
add a comment |
it should be
navA[i].children[0].style.cssText = "color:white;";
add a comment |
it should be
navA[i].children[0].style.cssText = "color:white;";
it should be
navA[i].children[0].style.cssText = "color:white;";
answered Dec 28 '18 at 7:51
David BrayDavid Bray
1778
1778
add a comment |
add a comment |
Try to set the style like this:
navA[i].setAttribute('style', 'color: white;');
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
add a comment |
Try to set the style like this:
navA[i].setAttribute('style', 'color: white;');
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
add a comment |
Try to set the style like this:
navA[i].setAttribute('style', 'color: white;');
Try to set the style like this:
navA[i].setAttribute('style', 'color: white;');
answered Dec 28 '18 at 7:35
Sandro SchaurerSandro Schaurer
1018
1018
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
add a comment |
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
the attribute added but the color doesn't change
– Dima Andrianov
Dec 28 '18 at 7:40
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%2f53955123%2fhow-to-change-the-style-element-html%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
Don't add
!importantunless you have no other choice.Most of the time there is a better solution. What is the css selector that over rules your property?– Mark Baijens
Dec 28 '18 at 7:47
Mark Baijens, I don't konw what you mean by the "the css selector that over rules your property" but I using bootstrap.
– Dima Andrianov
Dec 28 '18 at 7:57
It was more an answer to the comment that is now deleted which recommended to use the
!importanttag. This is mostly a bad way to go. Your problem however was that you changed to wrong element, so kinda irrelevant to your question.– Mark Baijens
Dec 28 '18 at 8:00