jQuery base

1 $() vs $

$("someSelector") returns a array. This is defiend in jQuery.prototype.

$.methodName is a method defined in jQuery...

 

2

methods below will stop the jQuery to manipulate the DOM until the document or window is ready...

the differences between them is, document just considerate the DOM, and window will considerate the whole page, this means until the waiting circle stops~

 

$(document).ready( // here comes lots of functions);

$(window).ready( // here comes lots of functions);

 

3 Conflicts 

var $j = jQuery.noConflict();

will make the $("...") the same as $j("...") in order to avoid conflicts from other liberaries also with an alias $...

 

4 Attribute

setter

$("selecteor").attr("someAttribute", someObject);

getter

$("selecteor").attr("someAttribute");

$( "a" ).attr( "href" ); // Returns the href for the first a element in the document

 

5 Prseudo-selector

When using the :visible and :hidden pseudo-selectors, jQuery tests the actual visibility of the element, not its CSS visibility or display properties.

jQuery looks to see if the element's physical height and width on the page are both greater than zero.

 

6 manipulating the DOM elements

.insertAfter()  VS .after().

.insertBefore() VS .before()

.appendTo() VS .append()

.prependTo() VS .prepend()

.remove() the selected elements will removed from the page, do returns something, but they are barely useless.

.detach() the selected elements will removed from the page, and this method will return something useful...

.empty() this method is used to the parent element in order to remove the children nodes~

 

7 create new elements

a : $("<p>This is a P</p>");

b : 

$( "<a/>", {
  html: "This is a <strong>new</strong> link",
  "class": "new", // Property names generally do not need to be quoted unless they are reserved words (as class is in this case).
  href: "foo.html"
  }
);
 
8 manipulating attributes
a : single  $( "#myDiv a:first" ).attr( "href" , "newDestination.html" );
b : multiple
$( "#myDiv a:first" ).attr({
    href: "newDestination.html",
    rel: "nofollow"
  }
);

 

 

转载于:https://www.cnblogs.com/voctrals/p/3707465.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值