jquery 获取元素
本帖最后由 liutao132 于 2013-01-18 16:39:34 编辑
<li class="where_left_iin where_bottom"><a class="where_bottom" href="javascript:void(0)" onclick="showRightContent(this)">Asia</a>
<ul class="where_left_in where_block">
<li><a href="javascript:void(0)" onclick="showRightContent1(this)">India </a></li>
<div class="where_xian">
</div>
</ul>
</li>
function showRightContent(obj) {
//如何给给<a href="javascript:void(0)" onclick="showRightContent1(this)">India </a>添加一个className(xxx)
}
本人对js不熟,自己试了一下
var slibs = obj.siblings("where_left_in where_block");
if (slibs != undefined && slibs.length > 0) {
var li = slibs[0].children;
if (li != undefined && li.length > 0) {
var aa = li[0].children;
aa[0].className = "where_come_on";
}
}
这个在 谷歌和火狐下面可以 IE下有问题
jquery
javascript
------解决方案-------------------- function getNextSibling(startBrother) {
endBrother = startBrother.nextSibling;
while (endBrother.nodeType != 1) {
endBrother = endBrother.nextSibling;
}
return endBrother;
}
function getNextSibling1(obj) {
if (obj.nextSibling.nodeType == 3) {
sibling = obj.nextSibling.nextSibling; // Moz. Opera
}
else {
sibling = obj.nextSibling; // IE
}
return sibling;
}
function getFirstChild(obj) {
&