Mark Steudel
Mark Steudel

Reputation: 1682

Jquery select textarea based on value

I'm trying to select textareas based on the value in them, I tried doing this:

alert( $('textarea[value="Type"]').length );

But I get zero.

Here's my textarea:

<textarea id="Title" name="title" rows="5" cols="29" class="textentry_verdana12pxItalic">Type</textarea>

Can I do this?

Upvotes: 3

Views: 2341

Answers (4)

Matt Ball
Matt Ball

Reputation: 359826

value is not an attribute of that textarea. That textarea's HTML attributes are id, name, rows, cols, and class. Try this instead:

$('textarea').filter(function ()
{
    return $(this).val() === 'Type';
}).length

.filter() API docs

Upvotes: 5

andres descalzo
andres descalzo

Reputation: 14967

try this (contains-selector):

alert($("textarea:contains('Type')").length);

Upvotes: 0

JAAulde
JAAulde

Reputation: 19560

Use the "contains" pseudo selector:

jQuery('textarea:contains(Type)')

Upvotes: 1

StefanS
StefanS

Reputation: 876

Try alert( $('textarea:contains("Type")').length );

Upvotes: 0

Related Questions