slandau
slandau

Reputation: 24052

Change text within input tag with Jquery

<input type="checkbox" name="Rates" class="RatesClass">Rates & Fees<br />

How can I change that text Rates & Fees dynamically, using Jquery?

Thanks!

How about this one that doesn't have a class defined?

<input type="checkbox" id="Value" name="Values">Values<br />

EDIT:

<input type="checkbox" id="RatesFees" name="Rates" class="RatesClass">Rates & Fees<br />
<input type="checkbox" id="RatesOnly" name="RatesSpecific" class="RatesClass">Rates (All-In-Rate Only)<br />

Upvotes: 1

Views: 2050

Answers (2)

Sam 山
Sam 山

Reputation: 42865

you need to add an id to the input.

<input id="myInput" type="checkbox" name="Rates" class="RatesClass">Rates & Fees<br/>

Then in your jQuery.

$('#myInput').html('Here is some HTML')

Upvotes: -1

user113716
user113716

Reputation: 322452

The simplest will be to unwrap the input DOM element from the jQuery object, and use the native nextSibling property to get the text node, then update its value with data.

$('input.RatesClass')[0].nextSibling.data = "new value";

If you're in an event handler, you'd just use this to refer to the element.

$('input.RatesClass').change(function() {
    this.nextSibling.data = "new value";
});

Upvotes: 2

Related Questions