tags:

views:

22

answers:

1
      $('#types').change(function() {
            var htmlToAppend = "<br/><input id='btnAddDictionary' type='button' value='Add Dictionary' />";
            if ($("#types").val() == 'enumType') {
                $(this).append(htmlToAppend); //problem is in there
                debugger;
            }
            else {
                //removebutton or not show it
            }
        });
+1  A: 

Try this:

  $('#types').change(function() {
        var htmlToAppend = "<br/><input id='btnAddDictionary' type='button' value='Add Dictionary' />";
        if ($(this).val() == 'enumType') {
            $(this).after(htmlToAppend);
            debugger;
        }
        else {
            $(this).next('br').remove();
            $(this).next('#btnAddDictionary').remove();
        }
  });
Nick Craver
$(this).append(htmlToAppend); problem is there. he appends after enumType value, but not after select box
loviji
@loviji - Clarify what you mean by "after select box"?
Nick Craver
I mean: add html button element after html SELECT element.<select id="types" ><option value="int">integer</option><option value="enumType">enumerable</option><input id='btnAddDictionary' type='button' value='Add Dictionary' /></select>
loviji
@loviji - Oh right, duh...fixed in answer, use `.after()` not `.append()`
Nick Craver