Leon Gaban
Leon Gaban

Reputation: 39018

How to target and change this label in jQuery

So this is what my HTML looks like:

<div class="modal-title"><label>Band</label>: Select one or more genres below</div>

If I just want to target that div (Which is inside of a div with the ID of #modal-1) and replace the content of the label, and not rewrite all the HTML. How would I do so?

What I've tried with no luck

$('#'+modal_ID '.modal-title').attr(label);

and it breaks my functionality

Upvotes: 0

Views: 131

Answers (2)

Blake Plumb
Blake Plumb

Reputation: 7199

The label is not an attribute but an element inside of the .modal-title div You need to get the element in your selector and change the text of the label to your desired label text. Here is a sample fiddle

$('#'+modal_ID+' .modal-title > label').text(label);
           // ^ you were missing the extra + symbol

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

Something like this may do the trick

$('#modal-1 .modal-title label').html(label);

Not sure what modal_ID, if required, your code would look like this

$('#' + modal_ID + ' .modal-title label').html(label);

Upvotes: 1

Related Questions