jQuery Lite: Choose jQuery

王林
Release: 2023-08-29 16:41:10
Original
544 people have browsed it

jQuery Lite: Choose jQuery< p>

<

custom jquery filters can select elements when used alone< h2>

it is not necessary to provide the actual element in conjunction with filter, such as $('div:hidden')< code>. you simply pass filter separately wherever a selector expression required. <

<

some examples:

 selects all hidden $(':hidden'); div elements, then selects only even $('div').filter(':even'); pre>
copy after login< div>< div>

groping:hidden and :visible filters<

the custom :hidden< code> :visible< do take css visibility properties into account one would expect. the way determines whether an or visible if takes up any space document. specifically, offsetwidth< offsetheight< reported by browser greater than 0. this way, that might have display< value block< contained within display< 的值>none< accurately report it invisible.

check code carefully make sure you understand why returned true< code>, though selected < has inline of display:block< <!doctype html> <html lang=""en">" <body> <div id=""secondUL">" none;"> block;">< div> < <script <script> (function($){ returns true because parent hidden, so encapsulated reports zero offsetwidth offsetheight alert($('#childdiv').is(':hidden')); })(jquery); script> body>

use is() method return boolean value<

it often determine set actually contains specific element. using is()< we check current based on filter. will at least given if contained, false< returned. check following code: alert($('div').is('#i1')); false. wrapper no <div> alert($('div').is('#i2')); alert($('div').is(':hidden'));

obviously, second alert()< false our wrapper does contain id< attribute i2< ##. code>is() very convenient for determining p>

note: starting 1.3, strong>is() supports expressions. previously, complex expressions those containing hierarchy selectors (such , code>~, code>>) always code>true. p>filters are other internal functions. therefore, rules apply here also here. p>some developers use

is('.class') class. don't forget already this called code>hasclass('class'), which be multiple values. but honest, code>hasclass() just convenience around method.


you jquery

h2>you comma-separated first parameter function:

$('expression, expression, expression'). in words, limited using single elements. for example, example below, i three function. <div>jquery <p>is p> <ul> <li>best!< li> ul> (function ($) { alerts best! alert($('div, p, ul li').text()); inefficient way. alert($('div').text() + $('p').text() $('ul p>each dom added set. we methods operate these remember placed same wrapping an inefficient call function times, once each expression. wrapperset.length selection anything checking length. array property

length. code>length 0, know matches passed there code>id "nothere" page. guess what? it's there! "0" alert($('#nothere').length); it's obvious, length number - how many function.< strong>


create selecting elements

h2>it possible extend functionality engine creating your own filters. theory, everything part jquery. let's say want web page absolutely positioned. since doesn't

:positionabsolute yet, create own. absolute">absolute< <span span> <div>static< define extending $.expr[':'] $.expr[':'].positionabsolute="function" (element) $(element).css('position')="==" 'absolute'; }; how positioned? alert($(':positionabsolute').length); "4" alert($('div:positionabsolute').length); "2" p>the most important thing grasp default provided however, before time version selector, try

filter() specified could avoid writing code>:positionabsolute code>filter() code> previous example. remove from positioned $('div').filter(function () $(this).css('position')="==" }); $('*').filter(function

注释:< strong>有关创建自己的选择器的更多信息,我建议阅读以下内容:http: www.bennadel.com blog 1457-how-to-build-a-custom- jquery-selector.htm<

按数字顺序过滤与 关系过滤之间的差异<

jquery 提供了过滤器,用于通过集合中元素的数字上下文来过滤包装器集。<

这些过滤器是:<

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!