Wednesday, 28 August 2013

How to destroy a DOM element after appending it to an element in the same function

How to destroy a DOM element after appending it to an element in the same
function

pHere is the code, I'm not even sure why it works as well as it does, line
7 isn't even valid I don't think, so why is it doing what I want it to (it
reduces opacity to 0 of the lightbox and removes the loginDropDown
element)? The thing that really confuses me is why doesn't it function the
same when I remove line 7, when line 7 isn't even valid JQuery I just
typed it by accident, is this a bug and if so how do I get it to function
the same with valid code?/p precodefunction lightBox($this) { if
(!$('#lightBox').length gt; 0) { $('lt;div
id=lightBoxgt;lt;/divgt;').prependTo($this);
$(#lightBox).animate({opacity: '.4'}, 500); } else {
$(#lightBox).animate({opacity: '0'}, 500); $('lt;div
id=lightBoxgt;lt;/divgt;').delete(); } } /** login dropdown **/
$('a#loginDropdownBtn').click(function () { $this = $(this); if
($(this).hasClass('loginActive')) {
$('div#loginDropdown').removeClass('loginActive'); } else {
$('div#loginDropdown').addClass('loginActive'); lightBox($this); } return
false; }); /** login removal **/ $(document).click(function (event) { if
($(event.target).parents().index($('#loginDropdown')) == -1) { if
($('#loginDropdown').is(:visible)) {
$('div#loginDropdown').removeClass('loginActive'); } } }) /code/pre pIf I
use:/p precode $(#lightBox).animate({opacity: '0'}, 500);
$('#lightBox').remove(); /code/pre pThen it removes the element before
animating to 0 opacity and doesn't remove the loginDropDown./p

No comments:

Post a Comment