次のような 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"));
});