accessing the class names for link elements through javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    accessing the class names for link elements through javascript

    hi i
    i am facing an issue like i am making a show an hide div slide show and i have to show the highlighted link with the slide now i have that so called links / pagination inside a div
    Code:
    <div id="links" class="float-left">
                                    <div class="float-left"><a href="#." class="nav-button" onclick="getSlide(this.href,this);" id="link-1">1</a></div>
                                    <div class="float-left"><a href="#." class="nav-button" onclick="getSlide(this.href,this);" id="link-2">2</a></div>
                                    <div class="float-left"><a href="#." class="nav-button" onclick="getSlide(this.href,this);" id="link-3">3</a></div>
                                    <div class="float-left"><a href="#." class="nav-button" onclick="getSlide(this.href,this);" id="link-4">4</a></div>
                                    <div class="float-left"><a href="#." class="nav-button" onclick="getSlide(this.href,this);" id="link-5">5</a></div>
                                </div>
    i am using a javascript statement to access that main div to make the next link highlighted (for highlighting i have a class in css sheet ) when the user clicks on the next button i am using a javascript like follows to get the curent class name of the next link it is working alright in FIREFOX but not IE 6 ,7
    (didnt tested in IE 8 ) the following statement fails when i alerted it shows null , where as in FIREFOX it alerts the class name
    Code:
    document.getElementById("links").getElementsByTagName("a")[0].getAttribute("class");
    regards,
    Omer Aslam
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    its done it was because the

    getAttribute()--- when using firefox recognises "class" as parameter (in my case as i wanted to access the classs attribute)

    and

    getAttribute()--- when using IE recognises "className" as parameter (in my case as i anted to access the classs attribute) , using the camel style notation
    i called both of these methods as it wouldnot generate errors and it would bypass the statement that is not valid in the relevent browser
    regards,
    Omer Aslam

    Comment

    Working...