jquery选择器学习笔记

$("img").removeAttr("title");//移除指定元素属性值



$("p:last").addClass("lastp");//addclass 为指定元素添加class,p:last 为最后一个p元素

$("p:first").addClass('firstp');//同上,只不过是第一个p元素

$("p:last").removeClass();//移除指定元素class

$("p").toggleClass("highlight");//为指定元素

$("p").toggle(function(){//toggle() 为指定元素按click轮换执行两个函数

   $(this).addClass("hignlight");

},function(){

   $(this).removeClass('hignlight');

});



$("p").click(function(){//html()为指定元素追加内容

   var html = $("p").text();

   $("p").html(html);

})



$("div").eq(1).addClass("hignlight");//第二个div关联css类别



$("div").text($("img").attr("title"));//为指定元素标签设置内容,text()用法

var text = $("div").text();//获取所有div标签元素内容

var text = $("div.d1").text();//获取指定class为d1的div标签元素内容



$("p > a").hide();//隐藏p元素内的子链接,不包括孙链接
$("p a").hide();//隐藏p元素内的所有子链接,包括子、孙链接

$("p[@a]").hide();//隐藏属性中含有a属性的p标记

$("p:eq(0)").hide();//隐藏第一个p标记

$("div:visible").hide();//隐藏所有可见div



$("p:lt(5)").css('border','2px solid')//:lt(n) 索引小于n的元素

$("p:gt(2)").css('border','7px solid green')//:gt(n) 索引大于n的元素



$("p:parent").css('background','red');

$("div:contains('tt')").hide();//隐藏所有text包行tt的div元素

$("div:contains('ccc')").css('border','3px dotted');//添加calss为所有text包行ccc的div元素



$("input:text").css('border','2px solid');//input元素下text类添加class

$("input:text",'myform').css('border','3px solid');



$("input[@type]")//属性含type的所有input元素

$("input[@type=text]").val("change input type text1");//属性为type属性值为text的所有input元素

$("input[@type=radio]").val("change input type text1");//属性为type属性值为radio的所有input元素

$("img[@src*=sina]").css('border','4px solid');//获取src属性中包含sina字符的img元素的所有元素

$("img[@src^=http]").css('color','red');//获取src属性中包口 http 字符开始img元素的所有元素

$("img[@src$=gif]").css('background','green');//获取src属性中 gif 结束字符的img元素的所有元素

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值