Jquery Input Selectors

Just lately, its come to my attention thats its very hard to find a clear definition of how to use jquery to find the value of input selectors, so for my future refference and your here it is:

If you want to select a text input by name, use:

$("input[@name=nameGoesHere]").val()

If you want to find a select box’s value by name, use:

$("type[@name=nameGoesHere]").val()

Alternately to this you may wish to work out the value based on the type like this

$("type[@type=text]").val()

This can come in useful when you want to look for every instance of a text box or input field, which does have its uses. Overall this is of great help when you want to use jquery without having to attach classes and div’s willy nilly. I could go on to list every type of select possibility, but I wont instead you can get an extensive list of jquery selector here. Happy coding!

  • Digg
  • StumbleUpon
  • del.icio.us
  • Twitter
  • Google Bookmarks
  • email
  • Facebook
  • RSS

Talk to me