Jump to content
  • 0

getElementsByClassName


stars
 Share

Question

Не получается разобраться как нужно дописать код чтобы работал getElementsByClassName в ie... Ясно только одно что ie пока что не обзавелся такой функцией...

вот код страницы и сама страница http://stars124.narod.ru/js2.html

нид хэлп

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251" />
<title>Z-index</title>
<script type="text/javascript">
function color3(node){
var wrap = document.getElementById('wrap3')

var wrapDiv = wrap.getElementsByClassName("z")
var wrapDiv2 = wrap.getElementsByClassName("b")
var wrapDiv3 = wrap.getElementsByClassName("s")
var nodeDiv = node.getElementsByTagName('div').item(0)

for(var i = 0; i<wrapDiv.length; i++){
wrapDiv.item(i).className = 'm'
}
for(var i = 0; i<wrapDiv2.length;i++){
wrapDiv2.item(i).className = 's'
nodeDiv.className = 'b'
}

for(var i = 0; i<wrapDiv3.length;i++){
nodeDiv.className = 'b'
}
node.className = 'z'
}

</script>
<style type="text/css">
*{ margin: 0; padding:0}
body { margin: 50px;}

div#wrap3 { width: 600px; height: 100px; border: 1px solid #000; }
div.m { height: 100px; width: 100px; background: red; float:left;}
div.z { height: 100px; width: 300px; background: green; float:left; }
div.s { height: 96px; width: 200px; background: yellow; display: none; border: 2px dotted #F09; float:right; }
div.b { height: 96px; width: 200px; background: yellow; display: block; border: 2px dotted #F09; float:right; }


</style>
</head>
<body>
<div id="wrap3">
<div onclick="color3(this);" class="m">Проба1<div class="s">1111111</div></div>
<div onclick="color3(this);" class="m">Проба2<div class="s">2222222</div></div>
<div onclick="color3(this);" class="m">Проба3<div class="s">3333333</div></div>
<div onclick="color3(this);" class="z">Проба4<div class="b">4444444</div></div>
</div>
</body>
</html>

Edited by stars
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

проблема решилась путем создания функции специально для ie

document.getElementsByClassName = function(cl) {

var retnode = [];

var myclass = new RegExp('\\b'+cl+'\\b');

var elem = this.getElementsByTagName('*');

for (var i = 0; i < elem.length; i++) {

var classes = elem.className;

if (myclass.test(classes)) retnode.push(elem);

}

return retnode;

};

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy