aooga Posted May 4, 2009 Share Posted May 4, 2009 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'>? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Define destroy an element. There's removeChild(). I suggest Google-ing it before applying that method blindly like most people do. Quote Link to comment Share on other sites More sharing options...
aooga Posted May 5, 2009 Author Share Posted May 5, 2009 Would removechild remove the elements within the element? is there a way to replace <p id='1'></p> with <p id='1.1'></p> <p id='1.2'></p> ? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Why would you want to do that? Quote Link to comment Share on other sites More sharing options...
aooga Posted May 5, 2009 Author Share Posted May 5, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Just hide them. You don't have to change the ID. Set the span with whatever ID to display: none. Quote Link to comment Share on other sites More sharing options...
aooga Posted May 5, 2009 Author Share Posted May 5, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 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. Quote Link to comment Share on other sites More sharing options...
aooga Posted May 5, 2009 Author Share Posted May 5, 2009 Any better method to suggest? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Well, I say hide them so in the JavaScript and or AJAX, they're not flipping out by getting IDs of elements that DON'T exists. That was the problem I pointed out above. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.