By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,603 Members | 1,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,603 IT Pros & Developers. It's quick & easy.

changing value inside <link> tag

exoskeleton
100+
P: 104
hi dear experts...i dont know if im in the right forum but...if not please kindly move this thread..

my problem is that how to change value like this one:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function css_style(css_choice) {
  4.  
  5. document.getElementById("css_style").innerHTML="css_styles/style"+css_choice+".css";
  6.  
  7. }
  8. -->
  9. </script>
  10.  
[HTML]
<link href="<div id=css_style></div>" rel="stylesheet" type="text/css">
[/HTML]

I know this won't work...but i've done this if without that link tag...i can change the value of the div tag ... but what if i would like to place a value inside link tag particularly in the href value? just like the case above...

please help...TIA
Feb 9 '07 #1
Share this Question
Share on Google+
6 Replies

exoskeleton
100+
P: 104
hi dear experts... i think this is the right forum for this matter..
dear mods please erase my thread at css forum ..thank you
ok..this is my problem..i want to change the value of css through the use of radio button but i will not post everything .. just this particular part...i have 3 radio button on my php page, when i click 1 then it will directly go to this function:

Expand|Select|Wrap|Line Numbers
  1. function css_style(css_choice) {
  2.  
  3. document.getElementById("css_style").innerHTML="css_styles/style"+css_choice+".css";
  4. css_pick="css_styles/style"+css_choice+".css";
  5.  
  6. }
  7. -->
  8. </script>
  9.  
[HTML]
<link href="css_styles/style1.css" rel="stylesheet" type="text/css">
[/HTML]
i try this:
[HTML]
<link href="<div id=css_style></div>" rel="stylesheet" type="text/css">
[/HTML]
but i know it doesn't work but i have to try something...please help

here it work...
[HTML]<div id=css_style></div>[/HTML]

in the <div> tag it works of course..i can see the changeed of results each time i click the radio buttons..but what if i would like to change the value inside <link> particularly the href portion to change the css style...please help me dear experts...

thank you in advance...
Feb 9 '07 #2

dmjpro
100+
P: 2,476
try to do .......

try{
links = document.getElementsByTag('link')
links[0].attr_name = 'value u want to assign'
}catch(err)
{
alert(err.description);
}

send me the reply ------------- i am online
Feb 9 '07 #3

P: 10
hi dear experts...i dont know if im in the right forum but...if not please kindly move this thread..

my problem is that how to change value like this one:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function css_style(css_choice) {
  4.  
  5. document.getElementById("css_style").innerHTML="css_styles/style"+css_choice+".css";
  6.  
  7. }
  8. -->
  9. </script>
  10.  
[HTML]
<link href="<div id=css_style></div>" rel="stylesheet" type="text/css">
[/HTML]

I know this won't work...but i've done this if without that link tag...i can change the value of the div tag ... but what if i would like to place a value inside link tag particularly in the href value? just like the case above...

please help...TIA
try this:
assign your link tag an id.
<link id="YourLinkID" href="" rel="stylesheet" type="text/css">

then in your function:
<script language="JavaScript" type="text/javascript">
<!--
function css_style(css_choice) {
document.getElementById("YourLinkID").setAttribute ("href", "css_styles/style"+css_choice+".css");

}
-->
</script>


but a link is calling the stylesheet by using the URL in href at the time of LOADING, not after the page loaded, so even if you could change the URL in the href on the fly, there is no point to do so, because after you change href's value, the style used by the page does not change.

If you want to change the style on the fly, try thinking some other approaches.

BTW, this POST should be in JAVASCRIPT/AJAX forum, you may get more reply I think.
Feb 9 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Just set an id for the link and change the href:
[HTML]<link id="css_style" href="css_styles/style1.css" rel="stylesheet" type="text/css">[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function css_style(css_choice) {
  2. document.getElementById("css_style").href="css_styles/style"+css_choice+".css";
  3. }
See this page for the <link> DOM.
Feb 9 '07 #5

dmjpro
100+
P: 2,476
wow!!!!!!!!!!!!!
a new concept i got
lot of thanx

can't i use getElementById('id_name').href = "css_filename_with_path"
instead of using setAttribute.....

one more thing ...

a text box is there .... with id deb_mou

now look at my code .... carefully
document.getElementById('deb_mou').setAttribute('r eadonly') = true
and document.getElementById('deb_mou').readOnly = true

see two readonly spelling is different ..
are two codes work same

i am waiting for ur reply

thanx in advance
Feb 13 '07 #6

exoskeleton
100+
P: 104
try this:
assign your link tag an id.
<link id="YourLinkID" href="" rel="stylesheet" type="text/css">

then in your function:
<script language="JavaScript" type="text/javascript">
<!--
function css_style(css_choice) {
document.getElementById("YourLinkID").setAttribute ("href", "css_styles/style"+css_choice+".css");

}
-->
</script>


but a link is calling the stylesheet by using the URL in href at the time of LOADING, not after the page loaded, so even if you could change the URL in the href on the fly, there is no point to do so, because after you change href's value, the style used by the page does not change.

If you want to change the style on the fly, try thinking some other approaches.

BTW, this POST should be in JAVASCRIPT/AJAX forum, you may get more reply I think.
thank you very much sir Duye...i really appreciate it...more power
Feb 20 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.