removechild

Remove multiple elements with same name using removeChild?

十年热恋 提交于 2019-12-25 01:09:06
问题 I have an elements with multiple elements inside. The elements inside all have the same name. Is there away to have a function remove all of them? (refer to this question for example Remove multiple children from parent? 回答1: Here's a solution that removes the first level children with the specified name for the parent with the specified id. If you want to go deeper, you can recursively call it on the child elements you get inside (you'll have to add a parent parameter as well). function

Javascript: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

两盒软妹~` 提交于 2019-12-24 17:28:23
问题 i am trying to recreate a some practices from one of the courses. Its about to remove a li-item from an UL and append it to another UL. When i write my code in the following way all works finde var removeMeandAppendMe = function() { var parentLi = this.parentNode; var goneElement = incompleList.removeChild(parentLi); compleList.appendChild(goneElement); }; var li = incompleList.getElementsByTagName('li'); for (var i = 0; i < incompleList.children.length; i++) { var link = li[i]; var

Javascript not removing all elements within a div

狂风中的少年 提交于 2019-12-23 13:03:18
问题 This piece of javascript code is created to remove all inputs that are within a div function remove_inputs(){ var elements=document.getElementById('thediv').getElementsByTagName('input'); for(var i=0;i<elements.length;i++){ elements[i].parentNode.removeChild(elements[i]); } } I does remove only half of elements a call and I have to call it several times in order to remove all inputs. Please check this Jsfiddle to see it in action. 回答1: That's because you skip items while removing from the

Error with getElementById(id).remove() in IE11 [duplicate]

半城伤御伤魂 提交于 2019-12-23 09:23:03
问题 This question already has answers here : Remove an element from the DOM from reference to element only (3 answers) Closed 3 years ago . I have this code: document.getElementById(id).remove(); But, IE give me an error with this function. Do you know an other way for make this remove? 回答1: Use this code instead: var child = document.getElementById(id); child.parentNode.removeChild(child); 回答2: Use the pollyfill from MDN if (!('remove' in Element.prototype)) { Element.prototype.remove = function

Traversing nodes correctly - javascript childNodes

可紊 提交于 2019-12-20 07:37:12
问题 I am trying to make following piece of code to work for each child node once. THe function is also deleting the node as per logic, for more than one child node it never seems to traverse to each child node. //Deleting from child node var target =document.getElementById(element.name).childNodes[0]; if(target.hasChildNodes()) { var children = new Array(); children = target.childNodes; for(child in children) { if(children[child].tagName == 'DIV'){ //target.removeChild[child]; var deleteChild =

Greasemonkey is unable to find/modify/delete content? (on Twitch.tv)

≡放荡痞女 提交于 2019-12-20 05:31:44
问题 I'm trying to remove various games off the twitch sub-page "Game List" (twitch.tv/directory) but I'm getting nowhere. I've debugged with alert, timers and @run-at document-end to no avail, the script reaches the page correctly but once I try to manipulate content nothing happens. This is what I use to test it: // ==UserScript== // @name TwitchDeleteTest // @namespace to.be.continued // @include http*://*twitch.tv/directory* // @version 1 // @grant none // ==/UserScript== var rmLoL = document

Remove an element from the DOM from reference to element only

徘徊边缘 提交于 2019-12-17 09:37:03
问题 This is either very simple or impossible. I know I can do this: var element = document.getElementById('some_element'); element.parentNode.removeChild(element); ...but it feels messy. Is there a tidier - and universally supported - way to do the same thing? It's seems - to me at least - like there should be something like this: document.getElementById('some_element').remove(); ...but that doesn't work, and searching Google/SO has not yielded any alternative. I know it doesn't matter that much,

remove first or specific child node xpath

我与影子孤独终老i 提交于 2019-12-13 23:42:31
问题 this code get table. I want to remove first and second tr tag in the table. $data = array(); $table_rows = $xpath->query('//table[@class="adminlist"]/tr'); if($table_rows->length <= 0) { // exit if not found echo 'no table rows found'; exit; } foreach($table_rows as $tr) { // foreach row $row = $tr->childNodes; if($row->item(0)->tagName != 'tblhead') { // avoid headers $data[] = array( 'Name' =>trim($row->item(0)->nodeValue), 'LivePrice' => trim($row->item(2)->nodeValue), 'Change'=> trim($row

removeChild sometimes removes entire span and sometimes doesn't

[亡魂溺海] 提交于 2019-12-12 08:57:54
问题 I'm working on a rich text editor for iOS and have most of it working but running into endless problems ensuring that the cursor is visible in the viewport when the user starts typing. I came up with a novel approach: insert a span at the cursor position, scroll to the span, and then remove it. (I haven't gotten to only scrolling if the span is on-screen.) Here's what I wrote: document.addEventListener('keypress', function(e) { jumpToID(); }, false); function jumpToID() { var id =

How can I delete item from a nested XUL tree? [closed]

拈花ヽ惹草 提交于 2019-12-12 05:37:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I created a nested tree using XUL (no database was used to store items). I want to delete items from this tree by selecting the item (only 1 at a time) then click delete. I wrote Javascript function to delete as