次のような HTML Div (Twitter Bootstrap を使用して hide-show を使用していますdiv2
) があります。
HTML:
<div id="div1">
<button id="mybtn">Button</button>
<div id="div2" class="modal hide fade span12" style="display: none;">
<button id="anotherButton" data-char="">AnotherButton</button>
</div>
</div>
jQuery を使用して、data-char
をクリックしているときに の値を変更しようとしていmybtn
ます。しかし、成功しなければ原因div2
は隠されています。console.log($('#anotherButton'));
空の配列を返します。
jQuery または Javascript を使用して非表示の DOM にアクセスする方法はありますか?
*編集:*
これを試してもうまくいかない場合は、次を返しundefined
ます:
$('#mybtn').live('click', function(e)
{
//or e.preventDefault();
$('#anotherbutton').attr("data-char", "assigned");
alert($('#anotherbutton').attr("data-char"));
});