Error $parentelement Document.body.getelementsbytagname Is Not A Function
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn element.getelementsbytagname is not a function html2canvas more about Stack Overflow the company Business Learn more about hiring developers or posting
Form.getelementsbytagname Is Not A Function
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Xmldoc.getelementsbytagname Is Not A Function
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up TypeError getElementsByTagName is not a function issue up vote 3
Html2canvas Typeerror Element.getelementsbytagname Is Not A Function
down vote favorite I'm having trouble getting to the source of this problem. Basically the error message I am getting in my console is: TypeError: $(...).getElementsByTagName is not a function When I click through to the line it is occuring on it is here: var inputs = $('directoryresults').getElementsByTagName('input'); I'm not sure why this is happening as I have included jQuery in the header of the page itself: cannot read property 'getelementsbytagname' of undefined Does anyone have any ideas what might be causing this? javascript jquery share|improve this question asked Nov 10 '14 at 16:28 Javacadabra 1,86274897 w3schools.com/jsref/met_doc_getelementsbytagname.asp –jyrkim Nov 10 '14 at 16:31 a jQuery object is not a DOM node. –squint Nov 10 '14 at 16:34 This jQuery tutorial might be worth having a look at: learn.jquery.com/using-jquery-core/selecting-elements, learn.jquery.com/using-jquery-core/traversing –Felix Kling Nov 10 '14 at 16:43 add a comment| 5 Answers 5 active oldest votes up vote 5 down vote accepted Does anyone have any ideas what might be causing this? The object returned by the jQuery constructor doesn't have the .getElementsByTagName() method. $('selector') returns a jQuery object. .getElementsByTagName() is a native JavaScript method of DOM elements. To look for elements with a certain tagname using the jQuery object you currently have: var inputs = $('directoryresults input'); // OR var inputs = $('directoryresults').find('input'); To get a like-for-like node list that .getElementsByTagName() would return (note this isn't exactly the same, this will return an array where .getElementsByTagName() will return a HTMLCollection): var inputs = $('directoryresults input').get(); Note: directoryresults, I am assuming, is either a class or id of a DOM element. Either way you'll want to amend the
& Guides Learn the Web Tutorials References Developer Guides Accessibility Game development ...more docs Mozilla document.getelementsbyname is not a function Docs Add-ons Firefox WebExtensions Developer ToolsFeedback Get Firefox help Get web getelementsbytagname javascript development help Join the MDN community Report a content problem Report a bug Search Search document.getelementsbytagname( input ) Languages Español (es) Français (fr) 日本語 (ja) Polski (pl) Русский (ru) 中文 (简体) (zh-CN) Add a translation Edit Advanced Advanced History Print this article MDN Web http://stackoverflow.com/questions/26848368/typeerror-getelementsbytagname-is-not-a-function-issue technology For developers Web APIs Document Document.getElementsByTagName() Your Search Results Sheppy teoli MHasan milmazz A.Amarbold kscarfone Khodaidad_Basharmand BrianDiPalma ethertank Marcoos dbruant deceze rwaldron shyangs Joneff Matej Lednar Jürgen Jeka Hsivonen Mgjbot Ptak82 Andreas Wuest Nickolay Jabez BenoitL Fmadero Document.getElementsByTagName() In This Article SyntaxExampleNotesSpecificationsSee also Returns an HTMLCollection of elements with the given https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName tag name. The complete document is searched, including the root node. The returned HTMLCollection is live, meaning that it updates itself automatically to stay in sync with the DOM tree without having to call document.getElementsByTagName() again. Syntax var elements = document.getElementsByTagName(name); elements is a live HTMLCollection (but see the note below) of found elements in the order they appear in the tree. name is a string representing the name of the elements. The special string "*" represents all elements. The latest W3C specification says elements is an HTMLCollection; however, this method returns a NodeList in WebKit browsers. See bug 14869 for details. Example In the following example, getElementsByTagName() starts from a particular parent element and searches top-down recursively through the DOM from that parent element, building a collection of all descendant elements which match the tag name parameter. This demonstrates both Document.getElementsByTagName() and the functionally identical Element.getElementsByTagName(), which starts the search at a specific element within the DOM tree.
(destined for Firefox 3). So I went around and dug up all of the different, existing, http://ejohn.org/blog/getelementsbyclassname-speed-comparison/ implementations that I could find. Currently, implementations fall into one of three categories (with some straddling more than one): Pure DOMThis usually involves a calls to .getElementsByClassName("*") and traversing through all matched elements, analyzing each element's className attribute along the way. Generally, the fastest method is to use a is not pre-compiled RegExp to test the value of the className attribute. DOM Tree WalkerIs a less-popular means of traversing DOM documents by setting some simple parameters, as specified by the DOM Level 2 Spec. For example, you could traverse through all text nodes in a document (something that you can't is not a easily do in any other way). XPathThe most recent technique, to be popularized, was the use of XPath to find elements by classname. The implementation is generally simple: Building a single expressions and letting the XPath engine traverse through the document, finding all the relevant elements. I've chosen some implementations that were representative of each of these techniques. Tree Walker An implementation using the DOM Level 2 Tree Walker methods. Builds a generic filter function and traverses through all elements. [js]document.getElementsByClass = function(needle) { function acceptNode(node) { if (node.hasAttribute("class")) { var c = " " + node.className + " "; if (c.indexOf(" " + needle + " ") != -1) return NodeFilter.FILTER_ACCEPT; } return NodeFilter.FILTER_SKIP; } var treeWalker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_ELEMENT, acceptNode, true); var outArray = new Array(); if (treeWalker) { var node = treeWalker.nextNode(); while (node) { outArray.push(node); node = treeWalker.nextNode(); } } return outArray