kockburn
kockburn

Reputation: 17636

Set labelText of input with Bootstrap Switch

Description:

I went through Bootstrap Switch's documentation but it's not very clear how I'm supposed to change the labelText of the switch input.

Name      | Attribute      | Type  | Description                             | Values | Default
----------+----------------+-------+-----------------------------------------+--------+--------
labelText | data-label-text| String| Text of the center handle of the switch |  String| ' '

Here is what it's supposed to look like:

label on text label off text

I get that just with no text in the "Label" area.

What I've tried:

I can set the labelText by default this way:

$.fn.bootstrapSwitch.defaults.labelText = 'Label!';

but I'm not looking to set every single bootstrapSwitch labelText to "Label!" just one.

I tried $("#my-input").labelText("Label!"); but that didn't work (didn't expect it to)

Question:

How do I set the label text for one input with Bootstrap Switch?

Upvotes: 0

Views: 3927

Answers (2)

Alejandro Ciravegna
Alejandro Ciravegna

Reputation: 21

In Jquery I use:

$('#my-input').bootstrapSwitch('labelText', 'Label!');

Upvotes: 2

Prateek Jain
Prateek Jain

Reputation: 86

In HTML - Just change the value of "data-label-text" attribute.

<input id="my-input" type="checkbox" data-label-text="Label!">

OR

In JQuery

$("#my-input").siblings(".bootstrap-switch-label").text("Label!");

Upvotes: 3

Related Questions