jQuery wrap is forcing multiple document ready callbacks
I have the following code:
function CreateRoundbox(selector, scope) {
$(selector).wrap('<div class=\"' + scope + ' dialog\"><div class=\"bd\"><div class=\"c\"><div class=\"s\"></div></div></div></div>');
$('div.' + scope).prepend('<div class=\"hd\"><div class=\"c\"></div></div>').append('<div class=\"ft\"><div class=\"c\"></div></div>');
}
Whenever I use this function and the "wrap" method is called it causes the $开发者_如何学运维(document).ready() method to fire for a second time on the page. Here is the call to the function (this lives in a document ready block):
CreateRoundbox(".roundbox", "roundbox-wrapper");
Has anyone ran into this before? Am I using wrap wrong?
UPDATE
Fixed usage line, I accidentally added a dot in the scope literal
function CreateRoundbox(selector, scope) {
// v----> this will result to class=".roundbox-wrapper", which is, I guess, not the thing you want in there.. :)
$(selector).wrap('<div class=\"' + scope + ' dialog\"><div class=\"bd\"><div class=\"c\"><div class=\"s\"></div></div></div></div>');
$('div.' + scope).prepend('<div class=\"hd\"><div class=\"c\"></div></div>').append('<div class=\"ft\"><div class=\"c\"></div></div>');
// ^ ^
// | |--- look at scope.... then, look here at the second argument, CreateRoundbox(".roundbox", ".roundbox-wrapper");
// |--- look at the dot.... :) CreateRoundbox(".roundbox", ".roundbox-wrapper");
}
精彩评论