Jump to content

is there any way to destroy an element?


aooga

Recommended Posts

If my script will be creating and deleteing spans constantly, is there a way to delete the span itself or do I just have to keep it empty and change it's id to 'empty' or something?

Eg.:

<span id='1'>1</span>

<span id='2'>2</span>

Then a function creates 2.1 and 2.2 within span id='2':

<span id='2'><span id='2.1'></span><span id='2.2'></span></span>

Is there a way to get rid of <span id='2'>?

Link to comment
https://forums.phpfreaks.com/topic/156857-is-there-any-way-to-destroy-an-element/
Share on other sites

I've written a website with php where there are questions arranged as a linked list. I want to convert it to javascript and ajax. There will be default question, the ability to add and delete them etc.

So for instead if I start with:

<span id='1'>1</span>

<span id='2'>2</span>

I want to be able to add 1.5 and then delete 1. How do I create 1.5? If I put it right after 1 i.e.

<span id='1'>1 <span id='1.5'>1.5</span></span>, then deleting 1 will delete 1.5 too.

What should I do? Right now my best idea is rename <span id='1'> to <span id='blah'> and then innerHTML in it <span id='1'> and <span id='2'>, then rename blah to junk. But then after many modifications my page will filled with a bunch of 'junk' spans.

Okay, I suppose I will. It just seems so inelegant. And I suppose in theory, with enough edits, it could bog down performance. But I suppose it's very unlikely to ever reach that point.

Your method is very messy. It's really hard to keep track of all the removal and addition. You wouldn't know which ID comes next. It's sort of ridiculous when you think about it. :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.