views:

71

answers:

2

Hi Guys

I want Element by using class name

Now I am using GWT 2.0

Please help me

Thanks

A: 

https://developer.mozilla.org/en/DOM/document.getElementsByClassName

e: not supported natively in IE, so you'd have to extend document / make a global function with something like this: http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/ or use something like sizzle or jquery - thanks to comments below.

danp
Not supported in IE. http://www.quirksmode.org/dom/w3c_core.html#t11
patrick dw
Just realised, sorry. Bloody IE.. updated.
danp
Looks like we are being promised support in IE9.
Dale
+2  A: 

A number of solutions have been built to work around browsers that don't have native getElementsByClassName. If you use any of the modern javascript libraries (e.g. jQuery, Prototype), they will automatically spackle over these browser-specific gaps.

So, for example, with jQuery:

$('.foo').get();

returns all the DOM elements with class foo, in any browser.

If you only want this particular problem solved, and don't want to use a full library, you can try using something like The Ultimate GetElementsByClassName, which lets you have:

getElementsByClassName('foo')

Although it's a couple of years old, John Resig's comparison of various solutions to the problem is still valuable.

Ken Redler