Jquery常用的选择器有哪些
1、基本选择器:#id 、element 、.class 、* 、selector1,selector2,selectorN
2、层次选择器:ancestor descendant 、parent > child 、prev + next 、prev ~ siblings
3、基本过滤器选择器:first 、:last 、:not 、:even 、:odd 、:eq 、:gt 、:lt 、:header 、:animated
4、内容过滤器选择器:contains 、:empty 、:has 、:parent
5、可见性过滤器选择器:hidden 、:visible
6、属性过滤器选择器[attribute] 、[attribute=value] 、[attribute!=value] 、[attribute^=value] 、[attribute$=value] 、[attribute*=value] 、[attrSel1][attrSel2][attrSelN]
7、子元素过滤器选择器:nth-child 、:first-child 、:last-child 、:only-child
8、表单选择器:input 、:text 、:password 、:radio 、:checkbox 、:submit 、:image 、:reset 、:button、:file 、:hidden9、表单过滤器选择器:enabled 、:disabled 、:checked 、:selected
jquery方法用于隐藏被选中元素的方法
jQuery中的hide()方法可以用于隐藏被选中元素。该方法将目标元素的display属性设置为“none”,使其在页面上不可见。
通过选中需要隐藏的元素并调用hide()方法,可以快速有效地实现隐藏效果。
此外,hide()方法还可以接受时间参数,指定隐藏动画的持续时间和缓动效果。
可以使用show()方法来显示被隐藏的元素,或toggleClass()方法来切换元素的显示和隐藏状态。总之,jQuery提供了多种方法来控制元素的可见性,可以根据具体需求选择合适的方法。
Jquery搜索父元素操作方法
使用js或者jquery查找父元素、子元素经常遇到。可是用起来总容易混淆,这里统一总结了一下,以后用起来相信会方便好多
这里jquery向上查找父元素 用到的方法:
closest() parents() parent()
向下查找子元素
用到的方法:find() children()
js用的是 children[] 属性 !
jQuery给多个不同元素添加class样式的方法
jQuery可以通过addClass()方法给多个不同的html元素同时添加相同的class
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<div>This is some important text!</div>
<br>
<button>Add classes to elements</button>
</body>
</html>
还没有评论,来说两句吧...