tags:

views:

238

answers:

5

I see the following piece of code

input[type='button']text:visible:enabled:first

What does this code do. Which feature of jquery is this? Is this selector example? Any links to read more on it?

A: 

Heres a link to jQuery selectors

Colin
+4  A: 

That exact piece of code is not a valid selector, but if you split them up they are filters and they are used to make a selector.

$('input[type="button"]') // references <input type=button>

The others are just filters denoted by the colon.

:text //matches all input type=text
:visible //*tries* to return what elements are visible
:enabled //matches elements that are enabled
:first //grabs the first in the selector set.

Usage: $('el:visible')

Reference: http://docs.jquery.com/Selectors

meder
is this example also of selector -- $(this).focus().select();
KJai
No. Selectors *select* something, that just invokes a method called 'select'.
meder
By *select* I mean they return an array of html element(s).
meder
thank you very much for your asnwers. Is this some sort of a chaining mechanism to be able do focus().select()? any link to read more on it
KJai
A: 

That's probably intended to be a selector, yes. I don't think the input[type='button']text portion is going to work though.

The jQuery documentation has a good rundown of all the various selectors: http://docs.jquery.com/Selectors

Also check out SelectorGadget. It's an interactive selector building GUI that loads right into your browser.

Dave Ward
thanks dave ward
KJai
A: 

This is indeed a selector, assuming that it is in something like this $() or this $j(). If I am reading it right it is looking for:

input any input
[type='button']
with the type button that is :visible
:enabled
:first and the first such element.

(Unfortunately, as it stands it is also broken.)

See http://docs.jquery.com/Selectors

Sean Vieira
A: 
input[type='button']

Is a selector, though in jQurey it needs to be wrapped in $(" ") to do something.

This kind of selector is bigger than a jQuery feature, it's XPath http://www.w3schools.com/XPath/default.asp , which is a system of selecting pieces ("nodes") of XML. The HTML we use in web pages is a sort of XML and XPath is a type of statement you can apply to HTML if you want to find ('select') certain pieces of it.

So jQuery allows you to use XPath query statements as selectors. XPath queries are just one type of selector that jQuery provides access to, there are also CSS selectors http://www.w3schools.com/Css/css%5Fsyntax.asp, which is a different system. As other's have mentioned, read up on the jQuery selector documentation http://docs.jquery.com/Selectors, which should help explain a lot.

perrierism
thank you malatio
KJai
Upvoting is a nice way of saying thanks too.
perrierism