Stack Overflow
Stack Overflow

Reputation: 247

How can I get the text of a label using Jquery in this particular case ?

For example in the code below , I would like get the text Salutation of a the label tag with class description in the code below , tried to select the class but it's not working .. how can I select the text of the label uniquely according to the id of the label ?

<tr id="salutation_id" class="edit_tr" border="0">
    <td class="edit_td">
    <div id="salutation_id" class="unique_ids database_key">
    <span id="first_salutation_id">
    <h1 class="ui-widget-header">
    <label id="label_salutation_id" class="description">Salutation</label>
    </h1>
    </span>
    <input id="first_input_salutation_id" class="editbox" type="text" value="Salutation" style="display: none;">
    <div class="ui-widget-content">
    <ol class="ui-droppable ui-sortable" style="">
    <li class="placeholder">Add "Salutation" here</li>
    </ol>
    </div>
    </div>
    </td>
    </tr>

Upvotes: 0

Views: 372

Answers (3)

Sergio
Sergio

Reputation: 28845

If you want to get it with ID, this is the way: $('#label_salutation_id').text().

You mention "with class description", then you can use this: $('label.description').text(); if you just have one <label> element with that class.

Demo here

Upvotes: 3

Alex
Alex

Reputation: 7833

If you meant to select more than this one salutation, you can use:

jQuery('label.description')

to select all label elements with the class description.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324820

Even better:

var label = document.getElementById('label_salutation_id'),
    text = label.textContent || label.innerText;

Upvotes: 1

Related Questions