how to permanenlty remove a div using jQuery

余生颓废 提交于 2020-01-17 03:49:10

问题


I was trying to remove a certain div element from my HTML using jQuery I saw this Use jquery to remove a div with no children, the jquery remove methods work perfectly fine but the problem is of Persistence,

Actually i want to permanently remove that div for that person, i was storing this in cookies but the problem is this remove method doesn't actually remove the code so when I parse through the code to store it using the cookies i store the removed code also. is there any way i can achieve a permanent removal for particular person??

Thanks Pranay

Since many people are confused here is what I was trying to achieve http://virtser.net/inettuts/ this was demo of http://james.padolsey.com/javascript/inettuts-with-cookies/ where he extended functionality of his code by adding Cokkiee support to retain the widget positions.

This code works fine for moving editing and collapse or expanding widget. It saves everything in cookie but for delete this does't work. It delete the widget but when i try to save it in cookie since the div element is present in code it does't save the deleted item


回答1:


jQuery isn't ideal for permanent removal of elements from a page as it's stateless.

Its a client side wrapper for javascript to interact with the DOM. While in theory, you can have it remove elements from the DOM based on readable cookies a particular user may have after a page has loaded, it's not ideal when server side coding could handle this without much effort.




回答2:


to remove it permanently you have to use serverside language for example php




回答3:


You could revert the process and add the DIV for specific users instead, leaving the data in the .js instead.




回答4:


To remove DIV "permanently" you have to use serverside lang. The logic is simple:

  1. Remove DIV from HTML
  2. Save some info about user and removed DIV in cookies
  3. In serverside script you have to get cookie and check did user disable any div or not. If he did your script should skip DIV generation


来源:https://stackoverflow.com/questions/4565295/how-to-permanenlty-remove-a-div-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!