Reputation: 25645
var popupType1 = "<div id=\"layerpopuplock\" style=\"position:absolute; width:375px; height:170px; z-index:2; left: 2px; top: 50px; visibility: hidden; \">";
popupType1 += "<table width=\"375\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FF0000\">";
popupType1 += "<tr><td align=\"center\" bordercolor=\"#FFFFFF\" class=\"FacetBiggerFieldCaptionTD\" id=\"popupmessagelock\" nowrap>message</td></tr>";
popupType1 += "</table></div>";
$(popupType1).appendTo($('body'));
This piece of code doesn't work.
I tryied a console.log of $('body') and I see it empty, but OF COURSE the html is already here, and the body is present.
Which can be the reason $('body') is empty ?
SOLUTION:
Sorry for wasting your time. My assumption was wrong: html is already here
I corrected in this way and now it goes, sorrry !!!!
$(function() {
... previous code ...
});
Upvotes: 0
Views: 4066
Reputation: 382142
Replace your 2 last
popupType1 = ...
by
popupType1 += ...
to have an HTML string that makes sense.
Note also that it would be easier to see the result without the visibility: hidden;
in the div
style.
Upvotes: 8
Reputation: 3481
I see 3 points to pay attention to:
+=
... var longstr = str; longstr += str2;
.appendTo()
use a selector instead of an object reference ... $(..).appendTo('body');
jQuery.ready( ... );
to trigger your code? This handler ensures, all DOM nodes are ready while using your script and it will be inserted at the right place (not other nodes getting in the way, even tho the body node exists) jQuery API: .ready()additionally to 2: you could also use $('body').append(popupType1);
additionally to 3: it may depend where you call your script - for example script tags within the body may behave odd adding elements.
Upvotes: 3
Reputation: 1343
popupType1 += "<tr><td align=\"center\" bordercolor=\"#FFFFFF\" class=\"FacetBiggerFieldCaptionTD\" id=\"popupmessagelock\" nowrap>message</td></tr>";
popupType1 += "</table></div>";
You are missing the += from your last two popupType1 assignments.
Upvotes: 1