我想知道如何通过类名获取元素,这是 html 代码
<div class="header" id="parent">
<div class="child"></div>
<div class="head_container">
<img src="images/logo_picture.png" alt="" title="" class="logopic" />
<img src="images/logo_text.png" alt="" title="" class="logotext" />
<img src="images/head_line.jpg" title="" alt="" class="head_line" />
</div>
</div>
这是 jquery,这是问题,我有 getEelementById 的代码,但我想使用 getElementByClass。这是在任何元素上使用不透明度并防止子元素继承不透明度的方法。我将使用五六个时间类父,所以我需要getElementByClass方法
$(document).ready(function () {
function thatsNotYoChild(parentID) {
var parent = document.getElementById(parentID),
children = parent.innerHTML,
wrappedChildren = '<div id="children" class="children">' + children + '</div>',
x, y, w, newParent, clonedChild, clonedChildOld;
parent.innerHTML = wrappedChildren;
clonedChild = document.getElementById('children').cloneNode(true);
document.getElementById('children').id = 'children-old';
clonedChildOld = document.getElementById('children-old');
newParent = parent.parentNode;
newParent.appendChild(clonedChild);
clonedChildOld.style.opacity = '0';
clonedChildOld.style.filter = 'alpha(opacity=0)';
function doCoords () {
x = clonedChildOld.getBoundingClientRect().left;
y = clonedChildOld.getBoundingClientRect().top;
if (clonedChildOld.getBoundingClientRect().width) {
w = clonedChildOld.getBoundingClientRect().width; // for modern browsers
} else {
w = clonedChildOld.offsetWidth; // for oldIE
}
clonedChild.style.position = 'absolute';
clonedChild.style.left = x + 'px';
clonedChild.style.top = y + 'px';
clonedChild.style.width = w + 'px';
}
window.onresize = function () {
doCoords();
};
doCoords();
}
thatsNotYoChild('parent');
});