I am trying to remove elements and content before a link inside a div when the user clicks a button. What is the best way to do this?
<div id="dialog" class="window"> //will be inserted a <select> element and few text here //but I want to clear them after the user click a button <a href="#" class="close">Close it</a> // I want to keep this <a> link. </div>
My jquery
$('.model').click(function(e) { $("#dialog").empty(); //I can't use this because <a> will be deleted. Any better ideas? });
Thanks for the answer...
Just wrap all these elements in a div and delete them
$('#select-wrapper').remove();
or make it a little more friendly
$('#select-wrapper').fadeOut(500, function() { $(this).remove(); });
try putting the content you want to remove in your own div. Then there will be just jquery to hide / remove the div in the click event.
:
$('.model').click(function(e) { $("#dialog").children(":not(.close)").remove(); });
, .remove() close . , .clone(), :
.remove()
close
.clone()
$('.model').click(function(e) { $("#dialog a.close").clone(true).appendTo($("#dialog").empty()); });
a, , div , , ?
a
Why not just rewrite innerHTML with <a href="#" class="close">Close it</a>?
<a href="#" class="close">Close it</a>
I understand that if this link has somehow changed beyond your knowledge or control, then you will have to save it, but if it is not, then the one looking will do the trick.
Source: https://habr.com/ru/post/1747910/More articles:How to determine the size of a project (lines of code, function points, others) - project-managementJSF hides exceptions? - javaCounting the number of values between an interval - pythonUsing #define once for multiple source files - c ++The importance of phased assertions in unit tests - unit-testingWhat is the correct way to use auto_ptr for dynamically allocated arrays? - c ++Архитектура REST/ROA. Отправлять поиск по базе данных/запрос/фильтр/параметры сортировки по URL-адресу? (>, <, IN и т.д.) - restPython - checking user admin privileges - pythonExclude records matching subquery - sqlCss3 Transition on a transparent background, not working in Chrome 5 - htmlAll Articles