开发者

How to perform jquery actions on elements not yet visible

开发者 https://www.devze.com 2023-03-25 00:01 出处:网络
I have a textarea in a div that I need to call a jquery function on to activate my rich textbox.The div is initially hidden and becomes visible through a button click on the server side:

I have a textarea in a div that I need to call a jquery function on to activate my rich textbox. The div is initially hidden and becomes visible through a button click on the server side:

<div id="RichTextDiv" style="display:none">
 <textarea id="RichText" />
</div>

<script type="text/javascript" language="javascript">
  $(document开发者_运维百科).ready(function () {
    $("#RichText").markItUp(mySettings);
  }
</script>

The above code doesn't work because RichTextDiv is not visible during page load. I need to perform the markItUp() action on RichText as soon as it becomes visible. How can this be achieved in jquery?

Thanks...


You could just leave it visible initially

<div id="RichTextDiv">
    <textarea id="RichText" />
</div>

and MarkItUp and hide on ready

$(document).ready(function () {
    $("#RichText").markItUp(mySettings).hide();
}

or wire it up once your button is clicked:

$("input:button")click(function(){
    $("#RichText").show().markItUp(mySettings);
});    

all this said, I don't know why MarkItUp would only work on visible elements, seems odd


sjQuery selectors work on hidden divs. They don't work if the element in not in the DOM, but that doesn't seem do be the case here.

Could it be that the div's ID is RichTextDiv and your selector is RichText?

0

精彩评论

暂无评论...
验证码 换一张
取 消