div#choices
内部に複数の div があり、表示されるたびにボタン要素を表示/非表示 (トグル) するにはどうすればよいdiv#choices
ですか (デフォルトでは非表示になっています)。これは私がトグルするコードですdiv#choices
:
$('#choices').on("change", ":checkbox", function(e) {
var theName = $(this).attr('name');
var theID = $(this).attr('value');
var input = "";
input = '<span>' + capitalize(theName) + '<input name="input_' + theName + '[]" data-id="' + theName + '_' + theID + '" value="" placeholder="' + capitalize(theName) + '" /><br/></span>';
if ($(this).is(":checked")) {
$("#" + theName + '_choice_' + theID).find(':button').before(input);
$("#" + theName + '_choice_' + theID).show();
} else {
$("#" + theName + '_choice_' + theID).find(':not(button)').remove();
$("#" + theName + '_choice_' + theID).hide();
}
});
更新: jsFiddle を追加し、提案に基づいていくつかのコードに取り組んでいます
私が取り組んでいるコードの例を次に示します。
また、これは私が作成したコードですが、子divが非表示になっている場合でもボタンが残るため、成功しませんでした:
function toggleCreateVariationButton() {
var toggleThis = $("#choices").children('div').length > 1 && $('#choices').children('div').css('display') != "none" ? true : false;
$("button#create-variation").toggle(toggleThis);
}
入力をクローンするたびに関数を呼び出しますが、何が問題なのですか?