Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 720 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make button that removes div where it is located?

#1
I want to make button that removes div where button is located.

This current solution removes current div only temporary, BUT i want it completely be removed from this html file. Is that possible?

I am done so far:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="screen" type="text/css" href="styles.css"/>
<title>Orders</title>
<center>
<style>
div
{width:797px;
border:2px solid;
background-color:white;
text-align:left;
margin-bottom:2px;}
</style>
<script type="text/javascript">
function deleteline(buttonObj)
{
var node = buttonObj;
do
{
node = node.parentNode;
}
while
(node.nodeType != 1 && node.nodeName != 'div');
node.parentNode.removeChild(node);
}
</script>
</head>
<center><a href=panel.html>back</a></center>

<div>
<input type="button" onclick="deleteline(this)" value="Remove this DIV" />
</div>

Reply

#2
> BUT i want it completely be removed from this html file.

The point is all you can do using JavaScript can actually creates client-side changes, so if you really want to delete the div element from your html file, the only thing you can do is creating a Server-side API and do a XHR request to that API, then remove it on the server side.

The other way to simulate this is to set an ID on that div element and save the last state of this element in the client using localStorage, after it got deleted, like:

function deleteline(buttonObj){
var node = buttonObj;
do {
node = node.parentNode;
}
while (node.nodeType != 1 && node.nodeName != 'div');
node.parentNode.removeChild(node);

var deleted_divs = localStorage["deleted_divs"];
var deletedDivs = deleted_divs ? JSON.parse(deleted_divs) ? [];
deletedDivs.push(node.id);
localStorage["deleted_divs"] = JSON.stringify(deletedDivs);
}


then check it whenever the DOM gets loaded:

document.addEventListener("DOMContentLoaded", function(event) {
var deleted_divs = localStorage["deleted_divs"];
if(deleted_divs){
var deletedDivs = JSON.parse(deleted_divs),
i = 0,
l = deletedDivs.length;
for( ; i < l ; i++){
var el = document.getElementById(deletedDivs[i]);
if( el ){
el.parentNode.removeChild(el);
}
}
}
});
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through