Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hasAttribute not working in IE

Status
Not open for further replies.

kav123

Programmer
Joined
Jan 12, 2005
Messages
210
Location
GB
I am using hasAttribute method of DOM to search if a table has the 'class' attribute. It is working on Firefox, but does not work on IE 6 & 7.
Is there any other way of looking for attributes. Has anyone used jquery to look for a class in a table??
 
There is no [tt]hasAttribute[/tt] method in the IE DOM. If you want to check if a table has a class attribute you can simply check the value of [tt].className[/tt]

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Ok, i have used className. It now does what it should do, however, i am getting an error on the browser the 'className' is null or not an object. My page may have tables which do not have any classes at all. Is it caused by that. I have used the attributes array but nothing seems to be setting it right.

Any ideas!!!!

var t=document.getElementsByTagName("table");

for (var i=0; i<=t.length; i++)
{
alert(
if(t.className=="striped")
{
stripeTable(t);
}
}
 
It is caused like you said because you don't have class names supplied to every table in your table object array. If you know which tables you have to check the className on, you can just specify those tables, or you can just assign a dummy class name to all the tables that don't yet have a class name and put no CSS in the class description, that should work.


<.
 
Yes, but i have no control over the creation of tables, it is dynamically created from the backend. That should be it really, i will see what i can do. Thanks anyway.
 
Here is what I would do in your case then:

Code:
var t=document.getElementsByTagName("table");
    
    for (var i=0; i<=t.length; i++)
    {
        if(t[i].className && t[i].className=="striped")
        {
          stripeTable(t[i]);
        } 
    }

Oh and there is a syntax error in your code supplied above.
First try your old way without the 'alert(' in your code. If that doesn't work then try my code.


<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top