Is there any other parameter like `this` in div name.first in javascript
I see some thing like
$(#content).children(".p:first");
call the first <p>
tag, except first
, Is there any other parameter? thanks.
exaple:
<div id="content">
<p>aaa</p>
<p>bbb</p>
开发者_运维百科<p>ccc</p>
use $(#content).children(".p:first");
echo
<div id="content">
<p>aaa</p>
</div>
Is there any $(#content).children(".p:second");
or $(#content).children(".p:last");
can be set?
I'm still not absolutley sure what you are trying to do, but I guess you try to query for a specfic index from elements.
So let's assume you want to only grab the first <p>
tag which is a children from #content
, that would look like:
$('#content p:first')
which is aquivalent with
$('#content').find('p:first');
Same example for the last <p>
tag:
$('#content p:last');
If you need to query for an even more specific index, you can apply a :eq()
selector or the method .eq()
. Example for the second <p>
tag:
$('#content').find('p').eq(1); // zero based index, 1 is the second node
References: :first, :last, :eq, .eq()
Is there any $(#content).children(".p:second"); or $(#content).children(".p:last"); can be set?
:last
already exists - see the documentation here.
:second
is not there, but could be implemented the easy way:
$('p:first').next()
or, with a custom selector:
$.expr[':'].second= function(
objNode,
intStackIndex,
arrProperties,
arrNodeStack
) {
return intStackIndex == 1;
}
This now allows you to do $('element:second'). See the jsFiddle here: http://jsfiddle.net/6xY6D/
精彩评论