Select div by class name

I got this div ...

<div tabindex="0" class="button-base inline-block button aw-btn button-base-active">
    <input type="text" tabindex="-1" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow-x: hidden; overflow-y: hidden; position: absolute; ">
 </div>

in the middle of my page, it has no id, and I cannot edit HTML pages, I also can not use jQuery. Also trying to do this with IE7 and IE8.

The nightmare is here :)

The solution would be document.getElementsByClassName, but it is not compatible with ie7 and ie8.

This div is buried in about 10 divs, all of which look like a style without id, etc. The classes on this div are unique!

The only solution I see is to get ALL divs and loop them around hasAttriutes search.

Anyone have a better idea?

+1
source share
4 answers

Here's a cross-browser implementation getElementsByClassNamefor incompatible browsers ( quote ):

if (!document.getElementsByClassName)
{

    document.getElementsByClassName = function(classname)
    {
        var elArray = [];

        var tmp = document.getElementsByTagName("*");

        var regex = new RegExp("(^|\\s)" + classname + "(\\s|$)");
        for ( var i = 0; i < tmp.length; i++ ) {

            if ( regex.test(tmp[i].className) ) {
                elArray.push(tmp[i]);
            }
        }

        return elArray;

    };
}
+6
source

, . - , , DIV . , , ( ), .

0

XPaths . ...

0

jQuery/Sizzle. IE6 .:)

:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

:

jQuery('.class.otherclass.anotherclass')
0

All Articles