费话很少说,直接上代码
jquery 获取元素jquery
1 $("#test1").parent(); // 父节点 2 $("#test1").parents(); // 所有父节点 3 $("#test1").parents(".mui-content");//返回class为mui-content的父节点 4 $("#test1").children(); // 所有子节点 5 $("#test1").children("#test1"); //返回id为test1的子节点 6 $("#test1").contents(); // 返回id为test里面的全部内容,包括节点和文本 7 $("#test1").contents("#test1"); //返回id为test里面的id为#test1的节点和文本 8 $("#test1").prev(); // 上一个兄弟节点 9 $("#test1").prevAll(); // 以前全部兄弟节点 10 $("#test1").next(); // 下一个兄弟节点 11 $("#test1").nextAll(); // 以后全部兄弟节点 12 $("#test1").siblings(); // 全部兄弟节点 13 $("#test1").siblings("#test2"); //返回id为test2的兄弟节点 14 $("#test").find("#test1"); 选中id为test后代中 id为test1的节点
注意上面的方法 返回的是jquery 集合 须要继续用jq的方法操做或取值
若是想要转为dom 直接操做的只须要 取它的下标便可
如: $("#test1").parent()[0] 返回的就是dom节点dom