I tried looking at this post which has an almost identical title but despite trying the answer that appeared suitable, my code still isn’t working.
I’m creating an element outside of the dom like this:
var e = $('<div class="alert"><div class="messageBox"><h1>'+type+'</h1><p class="message">'+message+'</p></div></div>');
On the next line, I’m attempting to manipulate it.
$('.alert',e).width($(window).width()).height($(window).height());
As you can see, I tried to define the context for the selector (the suggestion I saw in the other post) but it isn’t working. Can someone point out to me what I’ve done wrong?
The
.alertdiv is already at the root of yourevariable DOM contents, so no need to use context parameter (that will cause to find inside your.alertdiv for another.alertdiv, which won’t find anything) so just do like this:If you were to assign some property to your
.messageBoxdiv, then it would work to use the context parameter like you did: