applying className to anchor doesn't work

Discussion in 'Javascript' started by odelya, Feb 10, 2008.

  1. odelya

    odelya Guest

    Hi guys,

    I have written the following code:

    document.getElementById('file').className = "theClass";

    while I have in HTML":
    <a id="file" class="hello" />

    But it make any influence on the <a />
    Why doesn't it work properly?


    Thanks
     
    odelya, Feb 10, 2008
    #1
    1. Advertising

  2. odelya

    Evertjan. Guest

    odelya wrote on 10 feb 2008 in comp.lang.javascript:

    > Hi guys,
    >
    > I have written the following code:
    >
    > document.getElementById('file').className = "theClass";
    >
    > while I have in HTML":
    > <a id="file" class="hello" />
    >
    > But it make any influence on the <a />
    > Why doesn't it work properly?


    What style did you want to assign to such an anchor?

    How did you find it did not work propperly?

    As in "properly" = "how I want it to work"?

    Or "properly" = "As it should work according to specs and logic"?

    An non-hreffed anchor,
    not being a visual or placable html element,
    cannot logically have cascading styles, methinks.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 10, 2008
    #2
    1. Advertising

  3. odelya

    odelya Guest

    On 10 פברו×ר, 19:37, "Evertjan." <>
    wrote:
    > odelya wrote on 10 feb 2008 in comp.lang.javascript:
    >
    > > Hi guys,

    >
    > > I have written the following code:

    >
    > > document.getElementById('file').className = "theClass";

    >
    > > while I have in HTML":
    > > <a id="file" class="hello" />

    >
    > > But it make any influence on the <a />
    > > Why doesn't it work properly?

    >
    > What style did you want to assign to such an anchor?
    >
    > How did you find it did not work propperly?
    >
    > As in "properly" = "how I want it to work"?
    >
    > Or "properly" = "As it should work according to specs and logic"?
    >
    > An non-hreffed anchor,
    > not being a visual or placable html element,
    > cannot logically have cascading styles, methinks.
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)


    Hi,
    The "theClass" is a class is CSS file, and the javascript is from a
    function that is being called when clicking on a button.
    I tried to change the non-hreffed anchor properties and non of them
    worked.
    So what way is there to change a non-hreffed anchore values?

    Thanks

    Odelya
     
    odelya, Feb 10, 2008
    #3
  4. odelya

    Guest

    On Feb 11, 4:52 am, odelya <> wrote:
    > On 10 פברו×ר, 19:37, "Evertjan." <>
    > wrote:
    >
    >
    >
    > > odelya wrote on 10 feb 2008 in comp.lang.javascript:

    >
    > > > Hi guys,

    >
    > > > I have written the following code:

    >
    > > > document.getElementById('file').className = "theClass";

    >
    > > > while I have in HTML":
    > > > <a id="file" class="hello" />

    >
    > > > But it make any influence on the <a />
    > > > Why doesn't it work properly?

    >
    > > What style did you want to assign to such an anchor?

    >
    > > How did you find it did not work propperly?

    >
    > > As in "properly" = "how I want it to work"?

    >
    > > Or "properly" = "As it should work according to specs and logic"?

    >
    > > An non-hreffed anchor,
    > > not being a visual or placable html element,
    > > cannot logically have cascading styles, methinks.

    >
    > > --
    > > Evertjan.
    > > The Netherlands.
    > > (Please change the x'es to dots in my emailaddress)

    >
    > Hi,
    > The "theClass" is a class is CSS file, and the javascript is from a
    > function that is being called when clicking on a button.
    > I tried to change the non-hreffed anchor properties and non of them
    > worked.
    > So what way is there to change a non-hreffed anchore values?
    >
    > Thanks
    >
    > Odelya


    The code that you have is correct. Please post a sample of the code
    that you can confirm as not working and the browser in which it's
    failing.
     
    , Feb 10, 2008
    #4
  5. odelya

    Evertjan. Guest

    odelya wrote on 10 feb 2008 in comp.lang.javascript:

    >> --

    >
    > Evertjan.


    [please do not quote signatures on usenet]

    > The "theClass" is a class is CSS file, and the javascript is from a
    > function that is being called when clicking on a button.
    > I tried to change the non-hreffed anchor properties and non of them
    > worked.


    Please elaborate on "non of them worked", how would you detect that?

    > So what way is there to change a non-hreffed anchore values?


    What non-hreffed anchor CSS value would you want
    and what effect would you want to see?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 10, 2008
    #5
  6. odelya

    Evertjan. Guest

    McKirahan wrote on 10 feb 2008 in comp.lang.javascript:

    > "odelya" <> wrote in message
    > news:...
    > On 10 ??????, 19:37, "Evertjan." <>
    > wrote:
    >> odelya wrote on 10 feb 2008 in comp.lang.javascript:
    >>
    >> > Hi guys,

    >>
    >> > I have written the following code:

    >>
    >> > document.getElementById('file').className = "theClass";

    >>
    >> > while I have in HTML":
    >> > <a id="file" class="hello" />

    >>
    >> > But it make any influence on the <a />
    >> > Why doesn't it work properly?

    >>
    >> What style did you want to assign to such an anchor?
    >>
    >> How did you find it did not work propperly?
    >>
    >> As in "properly" = "how I want it to work"?
    >>
    >> Or "properly" = "As it should work according to specs and logic"?
    >>
    >> An non-hreffed anchor,
    >> not being a visual or placable html element,
    >> cannot logically have cascading styles, methinks.
    >>


    [please do not quote signatures on usenet]

    > Hi,
    > The "theClass" is a class is CSS file, and the javascript is from a
    > function that is being called when clicking on a button.
    > I tried to change the non-hreffed anchor properties and non of them
    > worked.
    > So what way is there to change a non-hreffed anchore values?
    >
    >
    > Note that the anchor tag has a closing tag; thus:
    > <a ... />
    > should be:
    > <a ...></a>


    > The following works. How is your code different?


    My code? I did not supply any.

    >
    > <html>
    > <head>
    > <title>newClass.htm</title>
    > <script type="text/javascript">
    > function newClass() {
    > document.getElementById('file').className = "theClass";
    >}
    > </script>
    > <style type="text/css">
    > .hello { color:purple }
    > .theClass { color:red }
    > </style>
    > </head>
    > <body>
    > <a id="file" class="hello">Hello World</a>


    The difference is, that this is not an empty!!! non-hareffed anchor.

    > <hr><button onclick="newClass()">New Class</button>
    > </body>
    > </html>
    >
    >
    >




    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 10, 2008
    #6
  7. odelya wrote:
    > I have written the following code:
    >
    > document.getElementById('file').className = "theClass";
    >
    > while I have in HTML":
    > <a id="file" class="hello" />
    >
    > But it make any influence on the <a />
    > Why doesn't it work properly?


    Works as designed: your `a' element is empty. You have just not understood
    *XHTML* and why not to use it on the Web unless absolutely required:

    http://www.spartanicus.utvinternet.ie/no-xhtml.htm


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 13, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver S.

    classname::classname a type ?

    Oliver S., Sep 11, 2003, in forum: C++
    Replies:
    1
    Views:
    511
    White Wolf
    Sep 11, 2003
  2. Hongzheng Wang
    Replies:
    32
    Views:
    882
  3. Bernhard Sturm

    #top anchor doesn't work in FF

    Bernhard Sturm, Oct 31, 2007, in forum: HTML
    Replies:
    25
    Views:
    3,224
    dorayme
    Nov 1, 2007
  4. AAaron123
    Replies:
    3
    Views:
    476
    AAaron123
    Mar 16, 2009
  5. Ante Perkovic

    CSS: "tagname.classname" or ".classname"

    Ante Perkovic, Dec 22, 2003, in forum: Javascript
    Replies:
    2
    Views:
    111
Loading...

Share This Page