ozil
ozil

Reputation: 7117

Dynamic creating button using j query and displaying text on button

i am creating a button using J query like this

$('<input>', {
                'type': 'button',
                'text': 'Connect',
                'id':   'buttonId',
                'class': 'buttonClass',
                'style':  '1px solid red',
            }).appendTo('#myAppendToElement');

But it is not displaying the connect text on button. What I am missing.

Upvotes: 0

Views: 38

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

For a button input the text on the button comes from the value property:

$('<input>', {
  'type': 'button',
  'value': 'Connect',
  'id':   'buttonId',
  'class': 'buttonClass',
  'style':  'border: 1px solid red',
}).appendTo('#myAppendToElement');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myAppendToElement"></div>

Upvotes: 2

Related Questions