Dynamically added radio button does not trigger click function

Dynamically added radio button does not trigger click function

There is a office list of radio button that a user can click on that will display the office information in a div. I have an option for the user to add an office to a list of radio buttons. When the user fills out the form, the radio button successfully gets added to the list but the click function does not trigger therefore does not update the office information in the div. When I click the other radio buttons the div does get updated, just when I click the dynamically added radio button. I have tried using .delegate() to the click function since the radio button was added after the initial page load, but without success.

Any help would be greatly appreciated!!!

How the radio button is added:

$(document).on("click", "#addOffice", function() {
  var officeadd = $('#officeAddForm').serializeArray();
      url:      'officeadd.php',
      type:         "POST",
      data:         officeadd,
      dataType: "json", 
      success: function(data) {
              if(data.errorCode[0] === 'ok') {
                console.log('NO ERRORS');
                $('#officecontrolgroup > div.ui-controlgroup-controls').append('<input type="radio" name="office" id="office' + data.officeInfo[0] + '" value="' + data.officeInfo[0] + '"/><label for="office' + data.officeInfo[0] + '">' + data.officeInfo[1] + '</label>').trigger('create');
                var $office = '#office'+ data.officeInfo[0];

                    $($office).prop('checked', true).checkboxradio("refresh");

  return false;

Click function for the radio buttons named office:

$('input[name=office]:radio').on('click', function() {
var $value = $(this).val();
    url:        'officeget.php',
    type:       "POST",
    data:       {q: $value},
    dataType:   "json", 
    success: function(data) {
            $('#docsuite').html('Suite '+data.officeSuite).fadeIn(1000);
            $('#doccitystate').html(data.officeCity+', '+data.officeState+' '+data.officePostalCode).fadeIn(1000);


<form id="officeChoice" class="submition">

<fieldset id="officecontrolgroup" class="ui-corner-all ui-controlgroup ui-      controlgroup-vertical ui-mini" style="margin-top:0px; width:100%;" data- mini="true" data-role="controlgroup" aria-disabled="false" data-disabled="false" data-shadow="false" data-corners="true" data-exclude-invisible="true" data-  type="vertical" data-init-selector=":jqmData(role='controlgroup')">
<div class="ui-controlgroup-controls">
<div class="ui-radio">
<div class="ui-radio">
<div class="ui-radio">


For this to work I need to change the ‘click‘ to a ‘change‘ event.

$('#officeChoice').on('change','input[name=office]:radio', function() {...

Fiddle Demo

you would need to delegate the event

$(container).on('click', 'input[name=office]:radio', function() {

Because your radio button was non existent at the time the event was bound.

container is the closest ancestor element on your DOM in which the radio elements are present.