Trung Tran
Trung Tran

Reputation: 13721

How to get text of a label using for

How can I get the text of a label via the for selector? Here's my label:

<label for="startdate">Iteration Start</label>

Here's what I've tried:

$("label[for='startdate']").text();

But this returns "".

Can someone help?

Thanks in advance!

Upvotes: 0

Views: 35

Answers (1)

guradio
guradio

Reputation: 15555

alert($('label[for=startdate]').text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="startdate">Iteration Start</label>

Use attr selector

Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.

Upvotes: 1

Related Questions