I can't think a syntax to remove the text highlighted in yellow. the PicPanel div gets cleared also when I try to access the main panel
Asked
Active
Viewed 72 times
1

Halimbawa Dokumento
- 105
- 1
- 14
-
I do not understood your question. are you talking about `$('#id').html('') / $('#id').text('')` – Deepak Ingole Feb 06 '14 at 03:36
3 Answers
3
var parent = document.getElementById('ct100...');
parent.removeChild(parent.firstChild);
Here's the fiddle: http://jsfiddle.net/9B36K/
If you want to make sure that you're only removing the text node if it's there (and not accidentally removing something else when it's not there) use this:
var parent = document.getElementById('ct100...');
var child = parent.firstChild;
child.nodeType == 3 && parent.removeChild(child);

Joseph Silber
- 214,931
- 59
- 362
- 292
-
1
-
-
If you want to make sure it's text, you may want to loop through all child nodes and remove all that are text nodes (not sure if this is what the op want's however). – Johannes H. Feb 06 '14 at 03:46
-
@JohannesH. - I doubt that's what they want. It seems they want to remove the text node before that next div. – Joseph Silber Feb 06 '14 at 03:47
-
@JohannesH. Also, people should stop saying that. jQuery is already loaded. There is an API that is probably much more efficient than an average JS dev. can get his/hers. Not using it is just arrogance. Loading jQuery just to do that - is a totally different matter. – ZenMaster Feb 06 '14 at 03:48
-
1@ZenMaster - I could not possibly disagree more. This solution is exponentially faster than the jQuery one. – Joseph Silber Feb 06 '14 at 03:51
-
@ZenMaster It's not more effiecient, as it#s wriotten in javascript, therefore using the same API you could use yourself. But jQUery includes many fixes to browser bugs that may not be needed for your specific tasks, which creats an overhead. jQUery is fine for every slightely complex task - but for single operations that most likely work fine in every browser, it's an overkill. ALso, jQUery has to parse the query string first, and look for the specific element, while there is nothing more efficient than getElementById. You're right about it being loaded anyway, at least for non-mobile devices – Johannes H. Feb 06 '14 at 03:52
-
jQuery is no "cure all + make it simple" libbrary with now drawbacks. It's an awesome piece of software, no doubt. But one should still know about when to use it (andy why), and when to stick to plain JS. – Johannes H. Feb 06 '14 at 03:54
-
Again, this is not the place. And I wasn't talking about this API spcifically. In general, if you have jQuery, you'd be a fool to rewrite existing APIs (or not use them consistently) only to show how much of a JavaScript wizard you are. Claiming "Stop using jQuery" (not targeting you specifically) at all possible occasions is just as bad as http://zarjay.net/2012/03/20/jquery-is-really-great-and-does-all-things/ – ZenMaster Feb 06 '14 at 03:57
1
This is a text node and to remove it you'd need to filter it:
HTML:
<div id="root">
Some text to be removed.
<div>Some div not to be removed</div>
</div>
JavaScript (jQuery)
$('#root').contents().filter(function() {
return this.nodeType == 3; // this is a text node
}).remove();
See JSFiddle

ZenMaster
- 12,363
- 5
- 36
- 59
0
For an example:
<div id="parent">
Parent
<div id="child">child</div>
</div>
Try using this code snippet:
$("#parent").contents().filter(function(){
return (this.nodeType == 3);
}).remove();

jellyfication
- 170
- 2
- 12