开发者

jquery toggle in a pop up modal form

I want to toggle between a div on a pop-up modal form. The problem i see is the document.ready() function on the modal page, which tries to load the parent form. It distorts the whole page and tries to show automatica开发者_运维百科lly if i load the main parent form. Is there something like div.ready()? how do i include this code on my pop up modal form?

Toggle code here

<html>
<head>
<title>jQuery test page</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#clickMe").click(function() {
$("#textBox").toggle();
});
});
</script>
</head>
  <body>
  <a id="clickMe">Toggle my text</a>
  <br />
  <div id="textBox">This text will be toggled</div>
  </body>


Yes, such expressions like DOM_ELEMENT.ready() exists and very useful in scenarios like the one you are facing right now.

Update:

I found that this plugin is doing what you need : jQuery.elementReady()

Examples:

1: Change the source of a specific image as soon as it is loaded into the DOM (before the whole DOM is loaded).

$.elementReady('powerpic', function(){
    this.src = 'powered-by-jquery.png';
});

2: If you want to have the jQuery object instead of the regular DOM

element, use the $(this) function.
$.elementReady('header', function(){
    $(this).addClass('fancy');
});

3: Chain multiple calls to $.elementReady().

$.elementReady('first',  function(){ $(this).fancify(); })
 .elementReady('second', function(){ $(this).fancify(); });

4: Use the ‘$’ alias within your callback, even in noConflict mode.

jQuery.noConflict();
jQuery.elementReady('header', function($){
    $(this).addClass('fancy');
});

5: Change the polling interval to 100ms. This only works if $.elementReady() has not yet been called.

$.elementReady.interval_ms = 100;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜