Reputation: 23791
I have created a div template like
var Mask="<div style='width: 60%;display:none; height: 602px;opacity: 0.3;' id='mask'>Hello i'm here</div>";
Now is tere any way to apply .show()
jquery function to this div.
Upvotes: 0
Views: 626
Reputation: 23791
Use this
$("<div style='width: 60%; height: 602px;display:none; opacity: 0.3;' id='mask'>Hello i'm here</div>").appendTo("body");
$('#mask').show();
Upvotes: 0
Reputation: 115
Write the div to the screen using document.write
document.write(Mask);
You do not need to use show() or on() because it will be shown when written to the screen
Upvotes: 1
Reputation: 17930
You cannot show this div until you actually append it to the DOM. Once it is appended to an element it will automatically appear.
Please note that if you intend to append this div more then one time, you need to change id='mask'
to class='mask'
, as id must be unique.
Upvotes: 0
Reputation: 12705
if you are adding this div dynamically use $.on()
on
if this div was added in side the HTML (meaning not dynamically) use simple $("#mask").show()
Upvotes: 0
Reputation: 3173
No, but fear not. You can append that string to the body HTML and it will render using the .appendTo() function.
Upvotes: 0