jquery - Set tag css property, before appending the tag to the DOM -
i set dom div tag, using jquery append()
method
i want before putting, set div tag css property, illustration visibility: "hidden"
this doesn't work:
$(document).ready( function () { $(".child").css({ visibility: "hidden" }); $("body").append('<div class="child"></div>'); });
http://jsfiddle.net/sbafk/
how solve problem ?
your code cannot work since not create new css rule searches matching elements - , new element cannot found yet. easiest way create element, set css properties , add together dom:
var div = $('<div class="child"></div>').css('visibility', 'hidden'); $('body').append(div);
another alternative creating new css rule matching selector.
jquery html css
No comments:
Post a Comment