1

how do i retrieve a textbox's title and name using jquery?

manraj82
  • 5,929
  • 24
  • 56
  • 83

4 Answers4

10
$('#textbox').attr('title')
$('#textbox').attr('name')
Glennular
  • 17,827
  • 9
  • 58
  • 77
4

Textbox, like an input element? Depending on where it is in the document, your selector may vary, but I'll assume you've given it an id, so the HTML would look something like this:

<input type="text" title="tehTitle" name="tehName" id="textBox" />

Since jQuery selectors use CSS syntax we can target by id attribute:

$("input#textBox") // more to come...

You can then use the jQuery attr function to read it's title and name attribute.

var title = $("input#textBox").attr("title");
var name = $("input#textBox").attr("name");
Richard JP Le Guen
  • 28,364
  • 7
  • 89
  • 119
1

var attributeText = $("#textboxID").attr("attributeYouWantToRetrieve");

just replace title and name for attributeYouWantToRetrieve

eppdog
  • 423
  • 2
  • 11
0
var theTextBox = $('textarea');
var itsTitle = theTextBox.attr('title');
var itsName = theTextBox.attr('name');

Maybe you should do some more tutorials :|

Matt
  • 74,352
  • 26
  • 153
  • 180