Reputation: 13115
I want Element by using class name
Now I am using GWT 2.0
Please help me
Thanks
Upvotes: 19
Views: 74257
Reputation: 5607
It may be wiser to use document.querySelector
or document.querySelectorAll
, supported since IE8.
Have a look here:
https://developer.mozilla.org/docs/Web/API/document.querySelector https://developer.mozilla.org/docs/Web/API/document.querySelectorAll
Upvotes: 2
Reputation: 15241
https://developer.mozilla.org/en/DOM/document.getElementsByClassName
e: not supported natively in IE < 9, 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.
Upvotes: 15
Reputation: 23943
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.
Upvotes: 14